#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int n, k;
vector<pair<int, int>> v;
vector<int> 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});
}
// cout << mid << ':' << ' ';
// for(int c : ans) cout << c << ' ';
// cout << '\n';
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++) {
int x, y;
cin >> x >> y;
v[i] = {x + y, x - y};
}
sort(v.begin(), v.end());
// for(auto [x, y] : v) cout << '{' << x << ' ' << y << '}' << ' ';
// cout << '\n';
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(int c : ans)
cout << c << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
4052 KB |
Output is correct |
2 |
Correct |
88 ms |
4180 KB |
Output is correct |
3 |
Incorrect |
81 ms |
4036 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
308 ms |
7584 KB |
Output is correct |
2 |
Correct |
311 ms |
7584 KB |
Output is correct |
3 |
Correct |
74 ms |
3892 KB |
Output is correct |
4 |
Correct |
242 ms |
7324 KB |
Output is correct |
5 |
Correct |
259 ms |
7516 KB |
Output is correct |
6 |
Correct |
260 ms |
7608 KB |
Output is correct |
7 |
Correct |
211 ms |
6936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
268 ms |
7252 KB |
Output is correct |
2 |
Correct |
258 ms |
7244 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
268 ms |
7252 KB |
Output is correct |
2 |
Correct |
258 ms |
7244 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
4052 KB |
Output is correct |
2 |
Correct |
88 ms |
4180 KB |
Output is correct |
3 |
Incorrect |
81 ms |
4036 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
4052 KB |
Output is correct |
2 |
Correct |
88 ms |
4180 KB |
Output is correct |
3 |
Incorrect |
81 ms |
4036 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |