| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1282334 | trungcan | Road Construction (JOI21_road_construction) | C++17 | 1137 ms | 8276 KiB |
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define fi first
#define se second
using namespace std;
const int N = 250005;
int n, k;
ll num;
pll a[N];
vector<ll> ans;
bool check(ll x){
multiset<ll> s;
int j = 1, cnt = 0;
for (int i = 1; i <= n; ++i){
while (a[j].fi < a[i].fi - x){
s.erase(s.find(a[j].se));
++j;
}
for (multiset<ll>::iterator it = s.lower_bound(a[i].se - x); it != s.end() && *it <= a[i].se + x; ++it)
if (++cnt >= k) return 1;
s.insert(a[i].se);
}
return 0;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
if (fopen("test.inp", "r")){
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
cin >> n >> k;
for (int i = 1, u, v; i <= n; ++i){
cin >> u >> v;
a[i].fi = u + v; a[i].se = u - v;
}
sort(a + 1, a + n + 1);
ll l = 1, r = 4e9;
while (l <= r){
ll mid = l + ((r - l) >> 1);
if (check(mid)){
num = mid;
r = mid - 1;
} else
l = mid + 1;
}
--num;
multiset<pll> s;
int j = 1;
for (int i = 1; i <= n; ++i){
while (j < i && a[j].fi < a[i].fi - num){
s.erase(s.find(make_pair(a[j].se, a[j].fi)));
++j;
}
for (multiset<pll>::iterator it = s.lower_bound(make_pair(a[i].se - num, -(ll)4e9)); it != s.end() && (*it).fi <= a[i].se + num; ++it)
ans.push_back(max(abs(a[i].se - (*it).fi), abs(a[i].fi - (*it).se)));
s.insert(make_pair(a[i].se, a[i].fi));
}
sort(ans.begin(), ans.end());
for (ll x: ans) cout << x << "\n";
k -= (int)ans.size();
while (k--)
cout << num + 1 << "\n";
}
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... | ||||
