#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define abcorz ios_base::sync_with_stdio(false);cin.tie(0);
int n,k;
vector<pair<int,int>> v;
vector<int> ans;
const int INF=2e9;
int calc(pair<int,int> a,pair<int,int> b){
return max(abs(a.x-b.x),abs(a.y-b.y));
}
int f(int p){
ans.clear();
set<pair<int,int>> s;
for(int i=0,j=0;i<n;i++){
while(v[i].y-v[j].y>p){
s.erase(v[j++]);
}
auto it=s.lower_bound({v[i].x-p,-INF});
auto it1=s.upper_bound({v[i].x+p,INF});
while(it!=it1){
ans.push_back(calc(*it,v[i]));
it++;
}
if(ans.size()>=k)return 1;
s.insert(v[i]);
}
return 0;
}
int32_t main(){
abcorz;
cin>>n>>k;
for(int i=0;i<n;i++){
int a,b;cin>>a>>b;
v.push_back({a-b,a+b});
}
sort(all(v),[](pair<int,int> a,pair<int,int> b){return a.y<b.y;});
int l=0,r=2e9;
while(r-l>1){
int m=(l+r)>>1;
(f(m)?r:l)=m;
}
f(l);
while(ans.size()<k)ans.push_back(r);
sort(all(ans));
for(int j:ans){
cout<<j<<'\n';
}
return 0;
}
Compilation message
road_construction.cpp: In function 'int f(int)':
road_construction.cpp:27:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
27 | if(ans.size()>=k)return 1;
| ~~~~~~~~~~^~~
road_construction.cpp: In function 'int32_t main()':
road_construction.cpp:46:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
46 | while(ans.size()<k)ans.push_back(r);
| ~~~~~~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2837 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
281 ms |
5576 KB |
Output is correct |
2 |
Correct |
292 ms |
5444 KB |
Output is correct |
3 |
Runtime error |
1619 ms |
2097152 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
189 ms |
2508 KB |
Output is correct |
2 |
Correct |
242 ms |
2520 KB |
Output is correct |
3 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
189 ms |
2508 KB |
Output is correct |
2 |
Correct |
242 ms |
2520 KB |
Output is correct |
3 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2837 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2837 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |