#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
inline char readchar() {
const int S = 1<<20; // buffer size
static char buf[S], *p = buf, *q = buf;
if(p == q && (q = (p=buf)+fread(buf,1,S,stdin)) == buf) return EOF;
return *p++;
}
inline int nextint() {
int x = 0, c = readchar(), neg = false;
while(('0' > c || c > '9') && c!='-' && c!=EOF) c = readchar();
if(c == '-') neg = true, c = readchar();
while('0' <= c && c <= '9') x = x*10 + (c^'0'), c = readchar();
if(neg) x = -x;
return x; // returns 0 if EOF
}
const int inf=2e9+5;
int n,k;
vector<pair<int,int>> vec;
vector<ll> ans;
bool check(ll d){
int l=0;
set<pair<int,int>> S;
ans.clear();
for(int r=0;r<n;r++){
while(vec[l].f<max(-(ll)inf,(ll)vec[r].f-d)){
S.erase({vec[l].s,l});
l++;
}
auto it2=S.upper_bound({min((ll)inf,(ll)vec[r].s+d),inf});
for(auto it=S.lower_bound({max(-(ll)inf,(ll)vec[r].s-d),-inf});it!=it2;it++){
int x=(*it).s;
ans.push_back(max(abs((ll)vec[x].f-(ll)vec[r].f),abs((ll)vec[x].s-(ll)vec[r].s)));
if((int)ans.size()>=k) return true;
}
S.insert({vec[r].s,r});
}
return false;
}
int main() {_
n=nextint();
k=nextint();
for(int i=0;i<n;i++){
int x,y;
x=nextint();
y=nextint();
int xx=y+x;
int yy=y-x;
vec.push_back({xx,yy});
}
sort(all(vec));
ll l=0,r=(ll)4e9;
while(l<r){
ll mid=(l+r)/2;
if(check(mid)){
r=mid;
}
else{
l=mid+1;
}
}
check(l-1);
sort(all(ans));
while((int)ans.size()<k) ans.push_back(l);
for(auto v:ans){
cout<<v<<'\n';
}
return 0;
}
//maybe its multiset not set
//yeeorz
//laborz
Compilation message
road_construction.cpp: In function 'void setIO(std::string)':
road_construction.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
road_construction.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | freopen((s + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
122 ms |
5160 KB |
Output is correct |
2 |
Correct |
119 ms |
5068 KB |
Output is correct |
3 |
Correct |
102 ms |
5064 KB |
Output is correct |
4 |
Correct |
83 ms |
5064 KB |
Output is correct |
5 |
Correct |
102 ms |
3860 KB |
Output is correct |
6 |
Correct |
3 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
292 ms |
6796 KB |
Output is correct |
2 |
Correct |
282 ms |
6756 KB |
Output is correct |
3 |
Correct |
68 ms |
5072 KB |
Output is correct |
4 |
Correct |
237 ms |
6340 KB |
Output is correct |
5 |
Correct |
222 ms |
6572 KB |
Output is correct |
6 |
Correct |
217 ms |
6752 KB |
Output is correct |
7 |
Correct |
196 ms |
6348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
162 ms |
3540 KB |
Output is correct |
2 |
Correct |
233 ms |
3544 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
94 ms |
3540 KB |
Output is correct |
5 |
Correct |
266 ms |
3544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
162 ms |
3540 KB |
Output is correct |
2 |
Correct |
233 ms |
3544 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
94 ms |
3540 KB |
Output is correct |
5 |
Correct |
266 ms |
3544 KB |
Output is correct |
6 |
Correct |
360 ms |
3540 KB |
Output is correct |
7 |
Correct |
336 ms |
3544 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
278 ms |
3544 KB |
Output is correct |
11 |
Correct |
65 ms |
3544 KB |
Output is correct |
12 |
Correct |
270 ms |
3544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
122 ms |
5160 KB |
Output is correct |
2 |
Correct |
119 ms |
5068 KB |
Output is correct |
3 |
Correct |
102 ms |
5064 KB |
Output is correct |
4 |
Correct |
83 ms |
5064 KB |
Output is correct |
5 |
Correct |
102 ms |
3860 KB |
Output is correct |
6 |
Correct |
3 ms |
344 KB |
Output is correct |
7 |
Correct |
881 ms |
6152 KB |
Output is correct |
8 |
Correct |
860 ms |
6156 KB |
Output is correct |
9 |
Correct |
87 ms |
5264 KB |
Output is correct |
10 |
Correct |
421 ms |
5484 KB |
Output is correct |
11 |
Correct |
266 ms |
5468 KB |
Output is correct |
12 |
Correct |
333 ms |
6236 KB |
Output is correct |
13 |
Correct |
432 ms |
4628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
122 ms |
5160 KB |
Output is correct |
2 |
Correct |
119 ms |
5068 KB |
Output is correct |
3 |
Correct |
102 ms |
5064 KB |
Output is correct |
4 |
Correct |
83 ms |
5064 KB |
Output is correct |
5 |
Correct |
102 ms |
3860 KB |
Output is correct |
6 |
Correct |
3 ms |
344 KB |
Output is correct |
7 |
Correct |
292 ms |
6796 KB |
Output is correct |
8 |
Correct |
282 ms |
6756 KB |
Output is correct |
9 |
Correct |
68 ms |
5072 KB |
Output is correct |
10 |
Correct |
237 ms |
6340 KB |
Output is correct |
11 |
Correct |
222 ms |
6572 KB |
Output is correct |
12 |
Correct |
217 ms |
6752 KB |
Output is correct |
13 |
Correct |
196 ms |
6348 KB |
Output is correct |
14 |
Correct |
162 ms |
3540 KB |
Output is correct |
15 |
Correct |
233 ms |
3544 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
94 ms |
3540 KB |
Output is correct |
18 |
Correct |
266 ms |
3544 KB |
Output is correct |
19 |
Correct |
360 ms |
3540 KB |
Output is correct |
20 |
Correct |
336 ms |
3544 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
278 ms |
3544 KB |
Output is correct |
24 |
Correct |
65 ms |
3544 KB |
Output is correct |
25 |
Correct |
270 ms |
3544 KB |
Output is correct |
26 |
Correct |
881 ms |
6152 KB |
Output is correct |
27 |
Correct |
860 ms |
6156 KB |
Output is correct |
28 |
Correct |
87 ms |
5264 KB |
Output is correct |
29 |
Correct |
421 ms |
5484 KB |
Output is correct |
30 |
Correct |
266 ms |
5468 KB |
Output is correct |
31 |
Correct |
333 ms |
6236 KB |
Output is correct |
32 |
Correct |
432 ms |
4628 KB |
Output is correct |
33 |
Correct |
1795 ms |
7344 KB |
Output is correct |
34 |
Correct |
1799 ms |
7516 KB |
Output is correct |
35 |
Correct |
1073 ms |
7008 KB |
Output is correct |
36 |
Correct |
518 ms |
7112 KB |
Output is correct |
37 |
Correct |
544 ms |
7360 KB |
Output is correct |
38 |
Correct |
607 ms |
6340 KB |
Output is correct |