Submission #794818

#TimeUsernameProblemLanguageResultExecution timeMemory
794818fuad27Road Construction (JOI21_road_construction)C++17
100 / 100
3463 ms28900 KiB
#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++) { long long 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(long long i:res)cout << i << "\n"; for(int i = res.size();i<k;i++)cout << lo << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...