We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
longmaximumPeople(vector<long>p,vector<long>x,vector<long>y,vector<long>r){set<long>townInCloud;map<int,long>popInCloud;vector<pair<long,pair<int,int>>>pos;for(inti=0;i<x.size();i++){pos.push_back({x[i],{0,i}});}for(inti=0;i<y.size();i++){pos.push_back({y[i]-r[i],{-i-1,0}});// lower_boundpos.push_back({y[i]+r[i],{i+1,0}});// upper_bound}sort(pos.begin(),pos.end());longres=0;for(inti=0;i<pos.size();i++){if(pos[i].second.first<0){//addintind=pos[i].second.first-1;townInCloud.insert(ind);}if(pos[i].second.first>0){// removeintind=-pos[i].second.first-1;townInCloud.erase(ind);}if(pos[i].second.first==0){// town in cloudintind=pos[i].second.second;if(townInCloud.size()==0){res+=p[ind];}elseif(townInCloud.size()==1){intposCloud=*(townInCloud.begin());popInCloud[posCloud]+=p[ind];}}}longans=0;for(autoi:popInCloud){ans=max(i.second,ans);}res+=ans;returnres;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Cloudy Day
You are viewing a single comment's thread. Return to all comments →