#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1000000000000000000
#define MOD 1000000007
int n, k, x, y;
pair<int, int> a[2500000];
vector<int> ans;
int dist(int x, int y) {
return max(abs(a[x].first-a[y].first), abs(a[x].second-a[y].second));
}
void solve(int d) {
ans.clear();
multiset<pair<int, int>> s;
int idx = 0;
for(int i = 0; i < n; i++) {
while(a[i].first - a[idx].first > d) {
s.erase({a[idx].second, idx});
idx++;
}
auto it = s.lower_bound({a[i].second-d, -1});
while(it != s.end() && it->first <= a[i].second+d) {
ans.push_back(dist(i, it->second));
if(ans.size() >= k) return;
it++;
}
s.insert({a[i].second, i});
}
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> k;
for(int i = 0; i < n; i++) {
cin >> x >> y;
a[i] = {x+y, x-y};
}
sort(a, a+n);
int l = 0, r = INF, m;
while(l < r) {
m = (l+r)/2;
solve(m);
if(ans.size() >= k) r = m;
else l = m+1;
}
solve(l-1);
sort(ans.begin(), ans.end());
while(ans.size() < k) ans.push_back(l);
for(int i : ans) cout << i << '\n';
}
Compilation message
road_construction.cpp: In function 'void solve(long long int)':
road_construction.cpp:27:27: 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]
27 | if(ans.size() >= k) return;
| ~~~~~~~~~~~^~~~
road_construction.cpp: In function 'int32_t main()':
road_construction.cpp:47: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]
47 | if(ans.size() >= k) r = m;
| ~~~~~~~~~~~^~~~
road_construction.cpp:52:22: 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]
52 | while(ans.size() < k) ans.push_back(l);
| ~~~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
131 ms |
7180 KB |
Output is correct |
2 |
Correct |
135 ms |
7184 KB |
Output is correct |
3 |
Correct |
124 ms |
7116 KB |
Output is correct |
4 |
Correct |
141 ms |
7120 KB |
Output is correct |
5 |
Correct |
127 ms |
5900 KB |
Output is correct |
6 |
Correct |
4 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
319 ms |
13000 KB |
Output is correct |
2 |
Correct |
317 ms |
13004 KB |
Output is correct |
3 |
Correct |
105 ms |
7120 KB |
Output is correct |
4 |
Correct |
268 ms |
12752 KB |
Output is correct |
5 |
Correct |
290 ms |
12808 KB |
Output is correct |
6 |
Correct |
324 ms |
13008 KB |
Output is correct |
7 |
Correct |
244 ms |
12492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
172 ms |
11724 KB |
Output is correct |
2 |
Correct |
246 ms |
11732 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
97 ms |
9440 KB |
Output is correct |
5 |
Correct |
355 ms |
12096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
172 ms |
11724 KB |
Output is correct |
2 |
Correct |
246 ms |
11732 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
97 ms |
9440 KB |
Output is correct |
5 |
Correct |
355 ms |
12096 KB |
Output is correct |
6 |
Correct |
356 ms |
11816 KB |
Output is correct |
7 |
Correct |
327 ms |
11824 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
259 ms |
11816 KB |
Output is correct |
11 |
Correct |
96 ms |
9428 KB |
Output is correct |
12 |
Correct |
386 ms |
12096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
131 ms |
7180 KB |
Output is correct |
2 |
Correct |
135 ms |
7184 KB |
Output is correct |
3 |
Correct |
124 ms |
7116 KB |
Output is correct |
4 |
Correct |
141 ms |
7120 KB |
Output is correct |
5 |
Correct |
127 ms |
5900 KB |
Output is correct |
6 |
Correct |
4 ms |
2396 KB |
Output is correct |
7 |
Correct |
775 ms |
10624 KB |
Output is correct |
8 |
Correct |
797 ms |
10624 KB |
Output is correct |
9 |
Correct |
123 ms |
7164 KB |
Output is correct |
10 |
Correct |
437 ms |
10112 KB |
Output is correct |
11 |
Correct |
294 ms |
9852 KB |
Output is correct |
12 |
Correct |
348 ms |
10832 KB |
Output is correct |
13 |
Correct |
376 ms |
9420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
131 ms |
7180 KB |
Output is correct |
2 |
Correct |
135 ms |
7184 KB |
Output is correct |
3 |
Correct |
124 ms |
7116 KB |
Output is correct |
4 |
Correct |
141 ms |
7120 KB |
Output is correct |
5 |
Correct |
127 ms |
5900 KB |
Output is correct |
6 |
Correct |
4 ms |
2396 KB |
Output is correct |
7 |
Correct |
319 ms |
13000 KB |
Output is correct |
8 |
Correct |
317 ms |
13004 KB |
Output is correct |
9 |
Correct |
105 ms |
7120 KB |
Output is correct |
10 |
Correct |
268 ms |
12752 KB |
Output is correct |
11 |
Correct |
290 ms |
12808 KB |
Output is correct |
12 |
Correct |
324 ms |
13008 KB |
Output is correct |
13 |
Correct |
244 ms |
12492 KB |
Output is correct |
14 |
Correct |
172 ms |
11724 KB |
Output is correct |
15 |
Correct |
246 ms |
11732 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
97 ms |
9440 KB |
Output is correct |
18 |
Correct |
355 ms |
12096 KB |
Output is correct |
19 |
Correct |
356 ms |
11816 KB |
Output is correct |
20 |
Correct |
327 ms |
11824 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
259 ms |
11816 KB |
Output is correct |
24 |
Correct |
96 ms |
9428 KB |
Output is correct |
25 |
Correct |
386 ms |
12096 KB |
Output is correct |
26 |
Correct |
775 ms |
10624 KB |
Output is correct |
27 |
Correct |
797 ms |
10624 KB |
Output is correct |
28 |
Correct |
123 ms |
7164 KB |
Output is correct |
29 |
Correct |
437 ms |
10112 KB |
Output is correct |
30 |
Correct |
294 ms |
9852 KB |
Output is correct |
31 |
Correct |
348 ms |
10832 KB |
Output is correct |
32 |
Correct |
376 ms |
9420 KB |
Output is correct |
33 |
Correct |
1548 ms |
15796 KB |
Output is correct |
34 |
Correct |
1625 ms |
15720 KB |
Output is correct |
35 |
Correct |
1034 ms |
15216 KB |
Output is correct |
36 |
Correct |
583 ms |
16012 KB |
Output is correct |
37 |
Correct |
553 ms |
15816 KB |
Output is correct |
38 |
Correct |
782 ms |
14432 KB |
Output is correct |