#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2.5e5 + 10;
int n, k;
array<int, 2> a[N];
map<int, vector<int>> mp;
vector<int> ans;
bool check(int di, bool add) {
// cout << "exh: " << di << '\n';
map<int, vector<int>> f;
int cnt = 0;
int lb = -1e18, rb = -1e18;
for (int i = 1; i <= n; i++) {
int x = a[i][0] - a[i][1], y = a[i][0] + a[i][1];
for (auto it = mp.lower_bound(lb); it != mp.end() && it->first < x - di; it++) {
auto& ri = it->second;
int lef = it->first;
for (auto& v : it->second) {
f[v].erase(f[v].begin());
// cout << v << " erase " << it->first << '\n';
}
}
for (auto it = mp.lower_bound(max(x - di, rb + 1)); it != mp.end() && it->first <= x; it++) {
auto& ri = it->second;
int lef = it->first;
for (auto& v : ri) {
f[v].push_back(lef);
// cout << v << " insert " << it->first << '\n';
}
}
for (auto it = f.lower_bound(y-di); it != f.end() && it->first <= y + di; it++) {
int lef = it->first;
auto& ri = it->second;
int sz = ri.size();
if (lef == y) sz--;
// cout << x << ' ' << y << ' ' << it->first << ' ' << sz << '\n';
// int ex = min(sz, k - cnt);
// cnt += ex;
// if (add) {
for (auto v : ri) {
if (lef == y && v == x) continue;
if (x == v && y > lef) continue;
// cout << '(' << x << ',' << y << ')' << ' ' << '(' << v << ',' << it->first << ')' << '\n';
cnt++;
if (add) ans.push_back(max(abs(it->first - y), abs(v - x)));
if (cnt >= k) return true;
// if (ans.size() >= k) return true;
}
// }
if (cnt >= k) {
// cout << "true!\n";
return true;
}
}
lb = max(lb, x - di);
rb = x;
}
// cout << "false!\n";
return false;
}
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i][0] >> a[i][1];
mp[a[i][0] - a[i][1]].push_back(a[i][0] + a[i][1]);
}
sort(a + 1, a + n + 1, [] (array<int, 2> x, array<int, 2> y) {
return x[0] - x[1] < y[0] - y[1];
});
for (auto& [st, v] : mp) sort(v.begin(), v.end());
int l = 1, r = 5e9;
while (l < r) {
int mid = (l + r) >> 1;
if (check(mid, 0)) r = mid;
else l = mid + 1;
}
// cout << "var: " << l-1 << '\n';
check(l-1, 1);
// for (auto x : ans) cout << x << ' ';
// cout << '\n';
sort(ans.begin(), ans.end());
while (ans.size() < k) ans.push_back(l);
for (int i = 0; i < k; i++) cout << ans[i] << '\n';
return 0;
}
/*
5 4
-2 2
-1 -1
2 0
2 2
2 -2
*/
Compilation message
road_construction.cpp: In function 'bool check(long long int, bool)':
road_construction.cpp:19:19: warning: unused variable 'ri' [-Wunused-variable]
19 | auto& ri = it->second;
| ^~
road_construction.cpp:20:17: warning: unused variable 'lef' [-Wunused-variable]
20 | int lef = it->first;
| ^~~
road_construction.cpp: In function 'int32_t main()':
road_construction.cpp:87:23: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
87 | while (ans.size() < k) ans.push_back(l);
| ~~~~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
129 ms |
5304 KB |
Output is correct |
2 |
Correct |
123 ms |
5308 KB |
Output is correct |
3 |
Correct |
96 ms |
5324 KB |
Output is correct |
4 |
Correct |
90 ms |
5368 KB |
Output is correct |
5 |
Correct |
107 ms |
4136 KB |
Output is correct |
6 |
Correct |
3 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3227 ms |
62224 KB |
Output is correct |
2 |
Correct |
3450 ms |
62336 KB |
Output is correct |
3 |
Correct |
104 ms |
5060 KB |
Output is correct |
4 |
Correct |
2675 ms |
61980 KB |
Output is correct |
5 |
Correct |
2650 ms |
62280 KB |
Output is correct |
6 |
Correct |
2486 ms |
62228 KB |
Output is correct |
7 |
Correct |
1769 ms |
61644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2647 ms |
59148 KB |
Output is correct |
2 |
Correct |
4675 ms |
59152 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1622 ms |
59156 KB |
Output is correct |
5 |
Correct |
768 ms |
7504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2647 ms |
59148 KB |
Output is correct |
2 |
Correct |
4675 ms |
59152 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1622 ms |
59156 KB |
Output is correct |
5 |
Correct |
768 ms |
7504 KB |
Output is correct |
6 |
Correct |
5954 ms |
59152 KB |
Output is correct |
7 |
Correct |
5494 ms |
59148 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
5345 ms |
54868 KB |
Output is correct |
11 |
Correct |
1511 ms |
59152 KB |
Output is correct |
12 |
Correct |
726 ms |
7532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
129 ms |
5304 KB |
Output is correct |
2 |
Correct |
123 ms |
5308 KB |
Output is correct |
3 |
Correct |
96 ms |
5324 KB |
Output is correct |
4 |
Correct |
90 ms |
5368 KB |
Output is correct |
5 |
Correct |
107 ms |
4136 KB |
Output is correct |
6 |
Correct |
3 ms |
336 KB |
Output is correct |
7 |
Execution timed out |
10017 ms |
24536 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
129 ms |
5304 KB |
Output is correct |
2 |
Correct |
123 ms |
5308 KB |
Output is correct |
3 |
Correct |
96 ms |
5324 KB |
Output is correct |
4 |
Correct |
90 ms |
5368 KB |
Output is correct |
5 |
Correct |
107 ms |
4136 KB |
Output is correct |
6 |
Correct |
3 ms |
336 KB |
Output is correct |
7 |
Correct |
3227 ms |
62224 KB |
Output is correct |
8 |
Correct |
3450 ms |
62336 KB |
Output is correct |
9 |
Correct |
104 ms |
5060 KB |
Output is correct |
10 |
Correct |
2675 ms |
61980 KB |
Output is correct |
11 |
Correct |
2650 ms |
62280 KB |
Output is correct |
12 |
Correct |
2486 ms |
62228 KB |
Output is correct |
13 |
Correct |
1769 ms |
61644 KB |
Output is correct |
14 |
Correct |
2647 ms |
59148 KB |
Output is correct |
15 |
Correct |
4675 ms |
59152 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1622 ms |
59156 KB |
Output is correct |
18 |
Correct |
768 ms |
7504 KB |
Output is correct |
19 |
Correct |
5954 ms |
59152 KB |
Output is correct |
20 |
Correct |
5494 ms |
59148 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
5345 ms |
54868 KB |
Output is correct |
24 |
Correct |
1511 ms |
59152 KB |
Output is correct |
25 |
Correct |
726 ms |
7532 KB |
Output is correct |
26 |
Execution timed out |
10017 ms |
24536 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |