Submission #972086

#TimeUsernameProblemLanguageResultExecution timeMemory
972086huutuanRoad Construction (JOI21_road_construction)C++14
100 / 100
1506 ms13660 KiB
#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 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...