This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=25e4+10;
int n, k;
pair<int, int> a[N];
bool check(int mid, bool trace, vector<int> &ans){
int cnt=0;
set<pair<int, int>> st;
for (int i=1, j=1; i<=n; ++i){
while (a[i].first-a[j].first>mid){
st.erase({a[j].second, j});
++j;
}
auto it=st.lower_bound({a[i].second-mid, (int)0});
while (it!=st.end() && abs(it->first-a[i].second)<=mid){
++cnt;
if (!trace && cnt>=k) return true;
if (trace) ans.push_back(max(abs(a[i].first-a[it->second].first), abs(a[i].second-it->first)));
++it;
}
st.insert({a[i].second, i});
}
return false;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> k;
for (int i=1; i<=n; ++i){
int x, y; cin >> x >> y;
a[i]={x+y, x-y};
}
sort(a+1, a+n+1);
int l=1, r=4e9;
vector<int> ans;
while (l<=r){
int mid=(l+r)>>1;
if (check(mid, 0, ans)) r=mid-1;
else l=mid+1;
}
check(r, 1, ans);
sort(ans.begin(), ans.end());
ans.resize(k, l);
for (int i:ans) cout << i << '\n';
return 0;
}
# | 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... |