| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1306549 | KhoaDuy | Road Construction (JOI21_road_construction) | C++20 | 275 ms | 7684 KiB |
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define int long long
int n,k;
const int MAXN=2*1e5;
vector<pair<ll,ll>> v;
vector<ll> bst;
int solve(ll limit,bool trace){
if(limit<=0){
return 0;
}
int curr=0;
set<pair<ll,int>> se;
int ptr=-1;
for(int i=0;i<n;i++){
while(ptr+1<i&&v[i].first-v[ptr+1].first>limit){
ptr++;
se.erase({v[ptr].second,ptr});
}
auto it=se.lower_bound({v[i].second-limit,0});
for(;it!=se.end()&&(*it).first<=v[i].second+limit;it++){
curr++;
if(trace){
int idx=(*it).second;
bst.push_back(max(abs(v[i].first-v[idx].first),(v[i].second-v[idx].second)));
}
if(curr>=k){
return curr;
}
}
se.insert({v[i].second,i});
}
return curr;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
if(fopen("input.txt","r")){
freopen("input.txt","r",stdin);
}
cin >> n >> k;
v.resize(n);
for(int i=0;i<n;i++){
cin >> v[i].first >> v[i].second;
v[i]={v[i].first-v[i].second,v[i].first+v[i].second};
}
sort(v.begin(),v.end());
ll low=1,high=4e9;
low--,high++;
while(high-low>1){
ll mid=((high-low)>>1)+low;
if(solve(mid,false)>=k){
high=mid;
}
else{
low=mid;
}
}
solve(low,true);
while(bst.size()<k){
bst.push_back(high);
}
sort(bst.begin(),bst.end());
for(int i=0;i<k;i++){
cout << bst[i] << endl;
}
}
Compilation message (stderr)
| # | 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... | ||||
