#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 250005;
const ll inf = 1e18;
pair<ll, ll> arr[MAXN];
vector<ll> dvec;
int nums, k;
bool gen(ll d){
dvec.clear();
set<pair<ll, ll>> active;
int lind = 0;
for (int i = 0; i < nums; i++){
ll x, y; tie(x, y) = arr[i];
while (arr[lind].first < x - d){
active.erase({arr[lind].second, arr[lind].first});
lind++;
}
for (auto it = active.lower_bound({y - d, -inf}); it != active.end() && it->first <= y + d; it++){
dvec.push_back(max(abs(x - it->second), abs(y - it->first)));
if (dvec.size() > k) return 0;
}
active.insert({y, x});
}
return 1;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> nums >> k;
for (int i = 0; i < nums; i++){
ll x, y; cin >> x >> y;
arr[i] = {x + y, x - y};
}
sort(arr, arr + nums);
ll l = 0, r = 4e9, ans;
while (l <= r){
ll m = (l + r) >> 1;
if (gen(m)){
ans = m;
l = m + 1;
}
else r = m - 1;
}
gen(ans);
sort(dvec.begin(), dvec.end());
for (ll x : dvec) cout << x << '\n';
for (int i = dvec.size(); i < k; i++) cout << ans + 1 << '\n';
}
Compilation message
road_construction.cpp: In function 'bool gen(ll)':
road_construction.cpp:21:20: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
21 | if (dvec.size() > k) return 0;
| ~~~~~~~~~~~~^~~
road_construction.cpp: In function 'int main()':
road_construction.cpp:48:54: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
48 | for (int i = dvec.size(); i < k; i++) cout << ans + 1 << '\n';
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
5132 KB |
Output is correct |
2 |
Correct |
83 ms |
5156 KB |
Output is correct |
3 |
Correct |
76 ms |
5072 KB |
Output is correct |
4 |
Correct |
74 ms |
5156 KB |
Output is correct |
5 |
Correct |
78 ms |
4052 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
317 ms |
7480 KB |
Output is correct |
2 |
Correct |
300 ms |
10584 KB |
Output is correct |
3 |
Correct |
69 ms |
5120 KB |
Output is correct |
4 |
Correct |
229 ms |
10444 KB |
Output is correct |
5 |
Correct |
243 ms |
10416 KB |
Output is correct |
6 |
Correct |
240 ms |
10708 KB |
Output is correct |
7 |
Correct |
225 ms |
10120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
271 ms |
4188 KB |
Output is correct |
2 |
Correct |
263 ms |
4348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
103 ms |
7252 KB |
Output is correct |
5 |
Correct |
290 ms |
9556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
271 ms |
4188 KB |
Output is correct |
2 |
Correct |
263 ms |
4348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
103 ms |
7252 KB |
Output is correct |
5 |
Correct |
290 ms |
9556 KB |
Output is correct |
6 |
Correct |
402 ms |
9424 KB |
Output is correct |
7 |
Correct |
348 ms |
9300 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
289 ms |
9304 KB |
Output is correct |
11 |
Correct |
96 ms |
7280 KB |
Output is correct |
12 |
Correct |
300 ms |
9704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
5132 KB |
Output is correct |
2 |
Correct |
83 ms |
5156 KB |
Output is correct |
3 |
Correct |
76 ms |
5072 KB |
Output is correct |
4 |
Correct |
74 ms |
5156 KB |
Output is correct |
5 |
Correct |
78 ms |
4052 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
740 ms |
8604 KB |
Output is correct |
8 |
Correct |
726 ms |
8852 KB |
Output is correct |
9 |
Correct |
73 ms |
5068 KB |
Output is correct |
10 |
Correct |
440 ms |
8084 KB |
Output is correct |
11 |
Correct |
230 ms |
7836 KB |
Output is correct |
12 |
Correct |
295 ms |
8624 KB |
Output is correct |
13 |
Correct |
406 ms |
7200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
5132 KB |
Output is correct |
2 |
Correct |
83 ms |
5156 KB |
Output is correct |
3 |
Correct |
76 ms |
5072 KB |
Output is correct |
4 |
Correct |
74 ms |
5156 KB |
Output is correct |
5 |
Correct |
78 ms |
4052 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
317 ms |
7480 KB |
Output is correct |
8 |
Correct |
300 ms |
10584 KB |
Output is correct |
9 |
Correct |
69 ms |
5120 KB |
Output is correct |
10 |
Correct |
229 ms |
10444 KB |
Output is correct |
11 |
Correct |
243 ms |
10416 KB |
Output is correct |
12 |
Correct |
240 ms |
10708 KB |
Output is correct |
13 |
Correct |
225 ms |
10120 KB |
Output is correct |
14 |
Correct |
271 ms |
4188 KB |
Output is correct |
15 |
Correct |
263 ms |
4348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
103 ms |
7252 KB |
Output is correct |
18 |
Correct |
290 ms |
9556 KB |
Output is correct |
19 |
Correct |
402 ms |
9424 KB |
Output is correct |
20 |
Correct |
348 ms |
9300 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
289 ms |
9304 KB |
Output is correct |
24 |
Correct |
96 ms |
7280 KB |
Output is correct |
25 |
Correct |
300 ms |
9704 KB |
Output is correct |
26 |
Correct |
740 ms |
8604 KB |
Output is correct |
27 |
Correct |
726 ms |
8852 KB |
Output is correct |
28 |
Correct |
73 ms |
5068 KB |
Output is correct |
29 |
Correct |
440 ms |
8084 KB |
Output is correct |
30 |
Correct |
230 ms |
7836 KB |
Output is correct |
31 |
Correct |
295 ms |
8624 KB |
Output is correct |
32 |
Correct |
406 ms |
7200 KB |
Output is correct |
33 |
Correct |
1577 ms |
13328 KB |
Output is correct |
34 |
Correct |
1536 ms |
13328 KB |
Output is correct |
35 |
Correct |
1010 ms |
12752 KB |
Output is correct |
36 |
Correct |
497 ms |
13656 KB |
Output is correct |
37 |
Correct |
492 ms |
13416 KB |
Output is correct |
38 |
Correct |
630 ms |
12044 KB |
Output is correct |