-
Notifications
You must be signed in to change notification settings - Fork 0
/
475.cpp
34 lines (29 loc) · 882 Bytes
/
475.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define INF 0x7FFFFFFF
int glo475 = 0;
int findRadius(vector<int> &houses, vector<int> &heaters) {
sort(houses.begin(), houses.end());
sort(heaters.begin(), heaters.end());
int s1 = houses.size(), s2 = heaters.size();
int p = 0;
int radius = 0;
int rp = 0;
for (int i = 0; i < s1; ++i) {
while (p<s2&&houses[i] > heaters[p]) p++;
if (p == 0) rp = heaters[p] - houses[i];
else if (p < s2) rp = min(heaters[p] - houses[i], houses[i] - heaters[p - 1]);
else rp = houses[i] - heaters[p - 1];
radius = max(radius, rp);
}
return radius;
}
//int main() {
// vector<int> houses = { 25921153, 510616708 }, heaters = { 771515668, 357571490, 44788124, 927702196, 952509530 };
// glo = glo + houses.size();
// cout << findRadius(houses,heaters) << endl;
// system("Pause");
// return 0;
//}