# week3

Heaters（from leetcode

Winter is coming! Your first job during the contest is to design a standard heater with fixed warm radius to warm all the houses.

Now, you are given positions of houses and heaters on a horizontal line, find out minimum radius of heaters so that all houses could be covered by those heaters.

So, your input will be the positions of houses and heaters seperately, and your expected output will be the minimum radius standard of heaters.

Note:

1. Numbers of houses and heaters you are given are non-negative and will not exceed 25000.
2. Positions of houses and heaters you are given are non-negative and will not exceed 10^9.
3. As long as a house is in the heaters' warm radius range, it can be warmed.

class Solution {
public:
int findRadius(vector<int>& houses, vector<int>& heaters) {
sort(houses.begin(),houses.end());
sort(heaters.begin(),heaters.end());
int x = 1,r = 0;
for(int i = 0; i < houses.size(); i++)
{
int t=abs(heaters[x-1]-houses[i]);
for(int j=x; j<heaters.size(); j++)
{
if(abs(heaters[j]-houses[i])<=t)
{
t=abs(heaters[j]-houses[i]);
x=j+1;

}
else
break;
}
r=max(r,t);
}
return r;
}
};