#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int n, k;
vector<pair<ll, ll>> v;
vector<ll> ans;
bool check(ll mid) {
ans.clear();
set<pair<ll, ll>> st;
st.insert({v[0].second, 0});
int l = 0;
for(int i = 1; i < n; i++) {
while(v[i].first - v[l].first > mid) {
st.erase({v[l].second, l});
l++;
}
auto it = st.lower_bound({v[i].second - mid, -1});
while(it != st.end() && abs(v[i].second - it->first) <= mid) {
ans.push_back({max(abs(v[i].first - v[it->second].first), abs(v[i].second - v[it->second].second))});
it++;
}
if((int)ans.size() > k) return 0;
st.insert({v[i].second, i});
}
return 1;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n >> k;
v.resize(n);
for(int i = 0; i < n; i++) {
ll x, y;
cin >> x >> y;
v[i] = {x + y, x - y};
}
sort(v.begin(), v.end());
ll l = 0, r = (ll)1e10;
while(r - l > 1) {
ll mid = (l + r) / 2;
if(check(mid)) l = mid;
else r = mid;
}
check(l);
// cout << l << ' ' << r << '\n';
sort(ans.begin(), ans.end());
while((int)ans.size() < k) ans.push_back(r);
for(ll c : ans)
cout << c << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
4996 KB |
Output is correct |
2 |
Correct |
102 ms |
4988 KB |
Output is correct |
3 |
Correct |
96 ms |
5068 KB |
Output is correct |
4 |
Correct |
96 ms |
5128 KB |
Output is correct |
5 |
Correct |
89 ms |
3868 KB |
Output is correct |
6 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
315 ms |
7488 KB |
Output is correct |
2 |
Correct |
311 ms |
7488 KB |
Output is correct |
3 |
Correct |
76 ms |
4944 KB |
Output is correct |
4 |
Correct |
253 ms |
7232 KB |
Output is correct |
5 |
Correct |
264 ms |
7476 KB |
Output is correct |
6 |
Correct |
251 ms |
7480 KB |
Output is correct |
7 |
Correct |
239 ms |
6824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
260 ms |
4180 KB |
Output is correct |
2 |
Correct |
252 ms |
4180 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
103 ms |
7040 KB |
Output is correct |
5 |
Correct |
315 ms |
9468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
260 ms |
4180 KB |
Output is correct |
2 |
Correct |
252 ms |
4180 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
103 ms |
7040 KB |
Output is correct |
5 |
Correct |
315 ms |
9468 KB |
Output is correct |
6 |
Correct |
402 ms |
9292 KB |
Output is correct |
7 |
Correct |
340 ms |
9212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
304 ms |
9220 KB |
Output is correct |
11 |
Correct |
100 ms |
7040 KB |
Output is correct |
12 |
Correct |
373 ms |
9472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
4996 KB |
Output is correct |
2 |
Correct |
102 ms |
4988 KB |
Output is correct |
3 |
Correct |
96 ms |
5068 KB |
Output is correct |
4 |
Correct |
96 ms |
5128 KB |
Output is correct |
5 |
Correct |
89 ms |
3868 KB |
Output is correct |
6 |
Correct |
3 ms |
340 KB |
Output is correct |
7 |
Correct |
727 ms |
7940 KB |
Output is correct |
8 |
Correct |
755 ms |
7944 KB |
Output is correct |
9 |
Correct |
90 ms |
5004 KB |
Output is correct |
10 |
Correct |
390 ms |
7252 KB |
Output is correct |
11 |
Correct |
238 ms |
7120 KB |
Output is correct |
12 |
Correct |
304 ms |
7932 KB |
Output is correct |
13 |
Correct |
344 ms |
6600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
4996 KB |
Output is correct |
2 |
Correct |
102 ms |
4988 KB |
Output is correct |
3 |
Correct |
96 ms |
5068 KB |
Output is correct |
4 |
Correct |
96 ms |
5128 KB |
Output is correct |
5 |
Correct |
89 ms |
3868 KB |
Output is correct |
6 |
Correct |
3 ms |
340 KB |
Output is correct |
7 |
Correct |
315 ms |
7488 KB |
Output is correct |
8 |
Correct |
311 ms |
7488 KB |
Output is correct |
9 |
Correct |
76 ms |
4944 KB |
Output is correct |
10 |
Correct |
253 ms |
7232 KB |
Output is correct |
11 |
Correct |
264 ms |
7476 KB |
Output is correct |
12 |
Correct |
251 ms |
7480 KB |
Output is correct |
13 |
Correct |
239 ms |
6824 KB |
Output is correct |
14 |
Correct |
260 ms |
4180 KB |
Output is correct |
15 |
Correct |
252 ms |
4180 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
103 ms |
7040 KB |
Output is correct |
18 |
Correct |
315 ms |
9468 KB |
Output is correct |
19 |
Correct |
402 ms |
9292 KB |
Output is correct |
20 |
Correct |
340 ms |
9212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
304 ms |
9220 KB |
Output is correct |
24 |
Correct |
100 ms |
7040 KB |
Output is correct |
25 |
Correct |
373 ms |
9472 KB |
Output is correct |
26 |
Correct |
727 ms |
7940 KB |
Output is correct |
27 |
Correct |
755 ms |
7944 KB |
Output is correct |
28 |
Correct |
90 ms |
5004 KB |
Output is correct |
29 |
Correct |
390 ms |
7252 KB |
Output is correct |
30 |
Correct |
238 ms |
7120 KB |
Output is correct |
31 |
Correct |
304 ms |
7932 KB |
Output is correct |
32 |
Correct |
344 ms |
6600 KB |
Output is correct |
33 |
Correct |
1677 ms |
13328 KB |
Output is correct |
34 |
Correct |
1602 ms |
13340 KB |
Output is correct |
35 |
Correct |
992 ms |
12560 KB |
Output is correct |
36 |
Correct |
535 ms |
13456 KB |
Output is correct |
37 |
Correct |
537 ms |
13412 KB |
Output is correct |
38 |
Correct |
686 ms |
12108 KB |
Output is correct |