#include <bits/stdc++.h>
using namespace std;
#define int long long
#ifdef DEBUG
#define dbg(...) printf(__VA_ARGS__);
#else
#define dbg(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb emplace_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 2023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
mt19937 rng(time(0));
#define maxn 250005
int n,k,x,y;
vi ans;
vii v;
set<ii> s;
int num(int d){
s.clear();
ans.clear();
int l=0;
for(int i=0;i<n;++i){
while(v[l].fi+d<v[i].fi)s.erase({v[l].se,l++});
auto it=s.lower_bound({v[i].se-d,-LINF});
while(it!=s.end()){
if(v[i].se+d>=it->fi){
ans.pb(max(abs(v[i].fi-v[it->se].fi),abs(v[i].se-v[it->se].se)));
++it;
}
else break;
if(sz(ans)==k)break;
}
if(sz(ans)==k)break;
s.insert({v[i].se,i});
}
return sz(ans);
}
main(){
sf("%lld%lld",&n,&k);
for(int i=0;i<n;++i){
sf("%lld%lld",&x,&y);
v.pb(x+y,x-y);
}
sort(all(v));
int lo=1,hi=2000000000,mid,res;
while(lo<=hi){
mid=lo+(hi-lo)/2;
if(num(mid)>=k)res=mid,hi=mid-1;
else lo=mid+1;
}
num(res-1);
sort(all(ans));
while(sz(ans)!=k)ans.pb(res);
for(int i:ans)pf("%lld\n",i);
}
Compilation message
road_construction.cpp: In function 'long long int num(long long int)':
road_construction.cpp:45:45: warning: operation on 'l' may be undefined [-Wsequence-point]
45 | while(v[l].fi+d<v[i].fi)s.erase({v[l].se,l++});
| ~^~
road_construction.cpp: At global scope:
road_construction.cpp:61:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
61 | main(){
| ^~~~
road_construction.cpp: In function 'int main()':
road_construction.cpp:62:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | sf("%lld%lld",&n,&k);
| ^
road_construction.cpp:64:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
64 | sf("%lld%lld",&x,&y);
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
116 ms |
4952 KB |
Output is correct |
2 |
Correct |
127 ms |
4996 KB |
Output is correct |
3 |
Incorrect |
77 ms |
4408 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
363 ms |
9368 KB |
Output is correct |
2 |
Correct |
345 ms |
9384 KB |
Output is correct |
3 |
Correct |
89 ms |
4832 KB |
Output is correct |
4 |
Correct |
293 ms |
12148 KB |
Output is correct |
5 |
Correct |
288 ms |
12308 KB |
Output is correct |
6 |
Correct |
271 ms |
12456 KB |
Output is correct |
7 |
Correct |
262 ms |
11760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
250 ms |
4404 KB |
Output is correct |
2 |
Correct |
296 ms |
4404 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
250 ms |
4404 KB |
Output is correct |
2 |
Correct |
296 ms |
4404 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
116 ms |
4952 KB |
Output is correct |
2 |
Correct |
127 ms |
4996 KB |
Output is correct |
3 |
Incorrect |
77 ms |
4408 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
116 ms |
4952 KB |
Output is correct |
2 |
Correct |
127 ms |
4996 KB |
Output is correct |
3 |
Incorrect |
77 ms |
4408 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |