#include<bits/stdc++.h>
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
const int N=250010;
int n, k;
vector<pair<long long,long long>> p;
vector<long long> res;
const long long inf=1e18;
bool check(long long dist) {
res.clear();
multiset<pair<long long, long long>> s;
int p1=0;
for(int i = 0;i<(int)p.size();i++) {
while(p[i].first-p[p1].first>dist) {
s.erase(s.find({p[p1].second, p[p1].first}));
p1++;
}
auto it1=s.lower_bound({p[i].second-dist, -inf}), it2=s.upper_bound({p[i].second+dist+1, -inf});
while(it1!=it2 and (int)res.size()<k) {
res.push_back(max(abs(p[i].first-(*it1).second), abs(p[i].second-(*it1).first)));
it1++;
}
s.insert({p[i].second, p[i].first});
}
return (int)res.size()==k;
}
int main () {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k;
for(int i = 0;i<n;i++) {
int x, y;
cin >> x >> y;
p.push_back({x+y, y-x});
}
sort(p.begin(), p.end());
long long lo = 0, hi = 1e10;
while(lo < hi) {
long long mid=(lo+hi-1)>>1;
if(check(mid)) {
hi=mid;
}
else {
lo=mid+1;
}
}
check(lo-1);
sort(res.begin(), res.end());
for(int i:res)cout << i << "\n";
for(int i = res.size();i<k;i++)cout << lo << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
4944 KB |
Output is correct |
2 |
Correct |
84 ms |
5000 KB |
Output is correct |
3 |
Incorrect |
78 ms |
5140 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
882 ms |
23004 KB |
Output is correct |
2 |
Correct |
864 ms |
23004 KB |
Output is correct |
3 |
Correct |
70 ms |
4992 KB |
Output is correct |
4 |
Correct |
834 ms |
23004 KB |
Output is correct |
5 |
Correct |
950 ms |
23004 KB |
Output is correct |
6 |
Correct |
971 ms |
23004 KB |
Output is correct |
7 |
Correct |
866 ms |
22304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2162 ms |
19768 KB |
Output is correct |
2 |
Correct |
2213 ms |
19892 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
889 ms |
19852 KB |
Output is correct |
5 |
Correct |
1909 ms |
19824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2162 ms |
19768 KB |
Output is correct |
2 |
Correct |
2213 ms |
19892 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
889 ms |
19852 KB |
Output is correct |
5 |
Correct |
1909 ms |
19824 KB |
Output is correct |
6 |
Correct |
2455 ms |
19860 KB |
Output is correct |
7 |
Correct |
2437 ms |
19804 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
4944 KB |
Output is correct |
2 |
Correct |
84 ms |
5000 KB |
Output is correct |
3 |
Incorrect |
78 ms |
5140 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
4944 KB |
Output is correct |
2 |
Correct |
84 ms |
5000 KB |
Output is correct |
3 |
Incorrect |
78 ms |
5140 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |