{"id":"32eba3d4-fe43-4e7b-a532-8129737a5e98","name":"Heaters","description":"1. Winter is coming! During the contest, your first job is to design a standard heater with a fixed warm radius to warm all the houses.\r\n2. Every house can be warmed, as long as the house is within the heater's warm radius range. \r\n3. Given the positions of houses and heaters on a horizontal line, return the minimum radius standard of heaters so that those heaters could cover all houses.\r\n4. Notice that all the heaters follow your radius standard, and the warm radius will the same.\r\n","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1 &lt;= houses.length, heaters.length &lt;= 3 * 10^4\r\n1 &lt;= houses[i], heaters[i] &lt;= 10^9\r\n","sampleCode":{"cpp":{"code":"#include <iostream>\n#include <vector>\n#include <utility>\n#include <cmath>\n#include <algorithm>\nusing namespace std;\n int findRadius(vector<int> &houses, vector<int> &heaters) {\n //write your code here\n return 0;\n }\n\n int main() {\n //input work\n int n = 0;\n cin>>n;\n vector<int> houses(n);\n\n for (int i = 0; i < n; i++) {\n cin>>houses[i];\n }\n\n int m = 0;\n cin>>m;\n vector<int> heaters(m);\n\n for (int i = 0; i < m; i++) {\n cin>>heaters[i];\n }\n\n cout<<findRadius(houses, heaters);\n return 0;\n }"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n public static int findRadius(int[]houses, int[]heaters) {\r\n //write your code here\r\n return 0;\r\n }\r\n\r\n public static void main(String[]args) {\r\n //input work\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[]houses = new int[n];\r\n\r\n for (int i = 0; i < n; i++) {\r\n houses[i] = scn.nextInt();\r\n }\r\n\r\n int m = scn.nextInt();\r\n int[]heaters = new int[m];\r\n\r\n for (int i = 0; i < m; i++) {\r\n heaters[i] = scn.nextInt();\r\n }\r\n\r\n System.out.println(findRadius(houses, heaters));\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"4\r\n1 2 5 7\r\n2\r\n1 4","sampleOutput":"3","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"59431e52-b234-4e27-9c3d-941858b551a6","name":"Heaters","slug":"heaters","type":1}],"next":{"id":"6b2e4355-f762-41f3-be65-0065cc5565c4","name":"Heaters","type":3,"slug":"heaters"},"prev":{"id":"0f491306-3a8e-493a-b908-7a48fe4c6703","name":"Largest Number MCQ","type":0,"slug":"largest-number-mcq"}}}

Heaters

1. Winter is coming! During the contest, your first job is to design a standard heater with a fixed warm radius to warm all the houses. 2. Every house can be warmed, as long as the house is within the heater's warm radius range. 3. Given the positions of houses and heaters on a horizontal line, return the minimum radius standard of heaters so that those heaters could cover all houses. 4. Notice that all the heaters follow your radius standard, and the warm radius will the same.

{"id":"32eba3d4-fe43-4e7b-a532-8129737a5e98","name":"Heaters","description":"1. Winter is coming! During the contest, your first job is to design a standard heater with a fixed warm radius to warm all the houses.\r\n2. Every house can be warmed, as long as the house is within the heater's warm radius range. \r\n3. Given the positions of houses and heaters on a horizontal line, return the minimum radius standard of heaters so that those heaters could cover all houses.\r\n4. Notice that all the heaters follow your radius standard, and the warm radius will the same.\r\n","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1 &lt;= houses.length, heaters.length &lt;= 3 * 10^4\r\n1 &lt;= houses[i], heaters[i] &lt;= 10^9\r\n","sampleCode":{"cpp":{"code":"#include <iostream>\n#include <vector>\n#include <utility>\n#include <cmath>\n#include <algorithm>\nusing namespace std;\n int findRadius(vector<int> &houses, vector<int> &heaters) {\n //write your code here\n return 0;\n }\n\n int main() {\n //input work\n int n = 0;\n cin>>n;\n vector<int> houses(n);\n\n for (int i = 0; i < n; i++) {\n cin>>houses[i];\n }\n\n int m = 0;\n cin>>m;\n vector<int> heaters(m);\n\n for (int i = 0; i < m; i++) {\n cin>>heaters[i];\n }\n\n cout<<findRadius(houses, heaters);\n return 0;\n }"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n public static int findRadius(int[]houses, int[]heaters) {\r\n //write your code here\r\n return 0;\r\n }\r\n\r\n public static void main(String[]args) {\r\n //input work\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[]houses = new int[n];\r\n\r\n for (int i = 0; i < n; i++) {\r\n houses[i] = scn.nextInt();\r\n }\r\n\r\n int m = scn.nextInt();\r\n int[]heaters = new int[m];\r\n\r\n for (int i = 0; i < m; i++) {\r\n heaters[i] = scn.nextInt();\r\n }\r\n\r\n System.out.println(findRadius(houses, heaters));\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"4\r\n1 2 5 7\r\n2\r\n1 4","sampleOutput":"3","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"59431e52-b234-4e27-9c3d-941858b551a6","name":"Heaters","slug":"heaters","type":1}],"next":{"id":"6b2e4355-f762-41f3-be65-0065cc5565c4","name":"Heaters","type":3,"slug":"heaters"},"prev":{"id":"0f491306-3a8e-493a-b908-7a48fe4c6703","name":"Largest Number MCQ","type":0,"slug":"largest-number-mcq"}}}
plane

Editor


Loading...

Heaters

medium

1. Winter is coming! During the contest, your first job is to design a standard heater with a fixed warm radius to warm all the houses. 2. Every house can be warmed, as long as the house is within the heater's warm radius range. 3. Given the positions of houses and heaters on a horizontal line, return the minimum radius standard of heaters so that those heaters could cover all houses. 4. Notice that all the heaters follow your radius standard, and the warm radius will the same.

Constraints

1 <= houses.length, heaters.length <= 3 * 10^4 1 <= houses[i], heaters[i] <= 10^9

Format

Input

Input is managed for you

Output

Output is managed for you

Example

Sample Input

4 1 2 5 7 2 1 4

Sample Output

3

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode