#include <bits/stdc++.h>
#define pb push_back
#define endl ("\n")
#define all(aa) aa.begin(), aa.end()
typedef long long ll;
using namespace std;
int main(){
int n, k;
cin >> n >> k;
vector<pair<ll, ll>> v(n);
for(int i = 0; i < n; i++) cin >> v[i].first >> v[i].second;
if(n <= 1000){
auto calc = [&](pair<ll, ll> a, pair<ll, ll> b){
return abs(a.first - b.first) + abs(a.second - b.second);
};
priority_queue<ll, vector<ll>, greater<ll>> pq;
for(int i = 0; i < n; i++){
for(int j = i + 1; j < n; j++){
pq.push(calc(v[i], v[j]));
}
}
for(int i = 0; i < k; i++){
cout << pq.top() << endl;
pq.pop();
}
exit(0);
}
auto calc = [&](pair<ll, ll> a, pair<ll, ll> b){
return abs(a.first - b.first) + abs(a.second - b.second);
};
sort(all(v));
auto check = [&](ll l){
int cnt = 0;
for(int i = 0; i < n; i++){
for(int j = i + 1; j < n; j++){
if(calc(v[i], v[j]) <= l)
cnt++;
else
break;
}
if(cnt >= k) break;
}
return cnt >= k;
};
ll tl = 1, tr = 1e12;
while(tr - tl > 1){
ll tm = (tl + tr) / 2;
if(check(tm))
tl = tm;
else
tr = tm;
}
priority_queue<ll, vector<ll>, greater<ll>> pq;
for(int i = 0; i < n; i++){
for(int j = i + 1; j < n; j++){
if(calc(v[i], v[j]) < tl)
pq.push(calc(v[i], v[j]));
else
break;
}
}
assert(pq.size() < k);
while( (int) pq.size() < k){
pq.push(tl);
}
for(int i = 0; i < k; i++){
cout << pq.top() << endl;
pq.pop();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |