#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,-1});
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=4000000000ll,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 |
120 ms |
4956 KB |
Output is correct |
2 |
Correct |
127 ms |
4984 KB |
Output is correct |
3 |
Correct |
113 ms |
4976 KB |
Output is correct |
4 |
Correct |
110 ms |
5092 KB |
Output is correct |
5 |
Correct |
119 ms |
3848 KB |
Output is correct |
6 |
Correct |
3 ms |
308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
350 ms |
9376 KB |
Output is correct |
2 |
Correct |
353 ms |
9380 KB |
Output is correct |
3 |
Correct |
93 ms |
4836 KB |
Output is correct |
4 |
Correct |
287 ms |
9412 KB |
Output is correct |
5 |
Correct |
305 ms |
9500 KB |
Output is correct |
6 |
Correct |
302 ms |
9508 KB |
Output is correct |
7 |
Correct |
272 ms |
8860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
225 ms |
4444 KB |
Output is correct |
2 |
Correct |
293 ms |
4456 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
156 ms |
7324 KB |
Output is correct |
5 |
Correct |
324 ms |
9604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
225 ms |
4444 KB |
Output is correct |
2 |
Correct |
293 ms |
4456 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
156 ms |
7324 KB |
Output is correct |
5 |
Correct |
324 ms |
9604 KB |
Output is correct |
6 |
Correct |
431 ms |
9336 KB |
Output is correct |
7 |
Correct |
397 ms |
9344 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
9 |
Correct |
1 ms |
296 KB |
Output is correct |
10 |
Correct |
314 ms |
9396 KB |
Output is correct |
11 |
Correct |
127 ms |
7180 KB |
Output is correct |
12 |
Correct |
383 ms |
9616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
4956 KB |
Output is correct |
2 |
Correct |
127 ms |
4984 KB |
Output is correct |
3 |
Correct |
113 ms |
4976 KB |
Output is correct |
4 |
Correct |
110 ms |
5092 KB |
Output is correct |
5 |
Correct |
119 ms |
3848 KB |
Output is correct |
6 |
Correct |
3 ms |
308 KB |
Output is correct |
7 |
Correct |
881 ms |
8020 KB |
Output is correct |
8 |
Correct |
863 ms |
7936 KB |
Output is correct |
9 |
Correct |
109 ms |
5092 KB |
Output is correct |
10 |
Correct |
472 ms |
7164 KB |
Output is correct |
11 |
Correct |
283 ms |
7164 KB |
Output is correct |
12 |
Correct |
354 ms |
7932 KB |
Output is correct |
13 |
Correct |
412 ms |
7076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
4956 KB |
Output is correct |
2 |
Correct |
127 ms |
4984 KB |
Output is correct |
3 |
Correct |
113 ms |
4976 KB |
Output is correct |
4 |
Correct |
110 ms |
5092 KB |
Output is correct |
5 |
Correct |
119 ms |
3848 KB |
Output is correct |
6 |
Correct |
3 ms |
308 KB |
Output is correct |
7 |
Correct |
350 ms |
9376 KB |
Output is correct |
8 |
Correct |
353 ms |
9380 KB |
Output is correct |
9 |
Correct |
93 ms |
4836 KB |
Output is correct |
10 |
Correct |
287 ms |
9412 KB |
Output is correct |
11 |
Correct |
305 ms |
9500 KB |
Output is correct |
12 |
Correct |
302 ms |
9508 KB |
Output is correct |
13 |
Correct |
272 ms |
8860 KB |
Output is correct |
14 |
Correct |
225 ms |
4444 KB |
Output is correct |
15 |
Correct |
293 ms |
4456 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
156 ms |
7324 KB |
Output is correct |
18 |
Correct |
324 ms |
9604 KB |
Output is correct |
19 |
Correct |
431 ms |
9336 KB |
Output is correct |
20 |
Correct |
397 ms |
9344 KB |
Output is correct |
21 |
Correct |
1 ms |
300 KB |
Output is correct |
22 |
Correct |
1 ms |
296 KB |
Output is correct |
23 |
Correct |
314 ms |
9396 KB |
Output is correct |
24 |
Correct |
127 ms |
7180 KB |
Output is correct |
25 |
Correct |
383 ms |
9616 KB |
Output is correct |
26 |
Correct |
881 ms |
8020 KB |
Output is correct |
27 |
Correct |
863 ms |
7936 KB |
Output is correct |
28 |
Correct |
109 ms |
5092 KB |
Output is correct |
29 |
Correct |
472 ms |
7164 KB |
Output is correct |
30 |
Correct |
283 ms |
7164 KB |
Output is correct |
31 |
Correct |
354 ms |
7932 KB |
Output is correct |
32 |
Correct |
412 ms |
7076 KB |
Output is correct |
33 |
Correct |
1801 ms |
15228 KB |
Output is correct |
34 |
Correct |
1799 ms |
15224 KB |
Output is correct |
35 |
Correct |
1164 ms |
14532 KB |
Output is correct |
36 |
Correct |
569 ms |
15344 KB |
Output is correct |
37 |
Correct |
548 ms |
15300 KB |
Output is correct |
38 |
Correct |
644 ms |
14056 KB |
Output is correct |