#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define C(Z) lower_bound(xVals, xVals + N, Z) - xVals
int N, K, F[250'001];
void add(int i, int v) {
for(i++; i <= N; i += i&-i) F[i] += v;
}
int get(int i, int v = 0) {
for(i++; i >= 1; i -= i&-i) v += F[i];
return v;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> N >> K;
int X[N], Y[N], byY[N], xVals[N], xPos[N];
for(int i = 0, x, y; i < N; ++i) {
cin >> x >> y;
X[i] = x + y;
Y[i] = x - y;
byY[i] = i;
xVals[i] = X[i];
}
sort(byY, byY + N, [&](int &i, int &j) {
return Y[i] < Y[j];
});
sort(xVals, xVals + N);
for(int i = 0; i < N; ++i)
xPos[i] = C(X[i]);
ll dist = -1, ext;
for(ll b = 1LL<<33; b /= 2; ) {
dist += b;
ll f = 0;
int p = 0;
fill(F, F + N + 1, 0);
for(int i : byY) {
while(Y[i] - Y[byY[p]] > dist)
add(xPos[byY[p++]], -1);
int l = C(X[i] - dist);
int r = C(X[i] + dist + 1) - 1;
f += get(r) - get(l-1);
add(xPos[i], 1);
}
if(f >= K) dist -= b;
else ext = K - f;
}
++dist;
set<array<int, 2>> on;
priority_queue<int> ans;
int p = 0;
for(int i : byY) {
while(Y[i] - Y[byY[p]] > dist)
on.erase({X[byY[p]], byY[p]}), ++p;
auto j = on.lower_bound({int(ll(X[i]) - dist), -1});
bool nxt = 1;
while(j != end(on) && (*j)[0] <= X[i] + dist) {
int o = (*j)[1];
int r = max(abs(X[i] - X[o]), Y[i] - Y[o]);
if(r == dist && !--ext) {
--dist;
while(Y[i] - Y[byY[p]] > dist) {
if((*j)[1] == byY[p]) ++j;
on.erase({X[byY[p]], byY[p]});
++p;
}
nxt = 0;
}
ans.push(-r);
if(nxt) ++j;
nxt = 1;
}
on.insert({X[i], i});
}
while(!empty(ans))
cout << -ans.top() << '\n', ans.pop();
}
Compilation message
road_construction.cpp: In function 'int main()':
road_construction.cpp:82:17: warning: 'ext' may be used uninitialized in this function [-Wmaybe-uninitialized]
82 | if(r == dist && !--ext) {
| ~~~~~~~~~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
55 ms |
3588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1659 ms |
11496 KB |
Output is correct |
2 |
Correct |
1666 ms |
11496 KB |
Output is correct |
3 |
Incorrect |
50 ms |
3448 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3214 ms |
11296 KB |
Output is correct |
2 |
Correct |
3297 ms |
11248 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3214 ms |
11296 KB |
Output is correct |
2 |
Correct |
3297 ms |
11248 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
55 ms |
3588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
55 ms |
3588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |