#include <bits/stdc++.h>
using namespace std;
long long N,K, ft[250005];
pair<long long,long long> A[250005];
vector< tuple<long long,long long,long long> > lst;
vector<long long> dis,ans;
set< pair<long long,long long> > s;
void update (long long x, long long v) {
x++;
while (x <= N) ft[x] += v, x += x & -x;
}
long long query (long long x) {
x++;
long long ans = 0;
while (x) ans += ft[x], x -= x & -x;
return ans;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> N >> K;
for (long long i = 0; i < N; ++i) {
long long x,y; cin >> x >> y;
A[i] = make_pair(x-y,x+y);
dis.push_back(x+y);
}
sort(dis.begin(),dis.end());
dis.resize(unique(dis.begin(),dis.end()) - dis.begin());
long long low = 0, high = 4e9+5;
while (high-low > 1) {
long long mid = (low+high)/2;
lst.clear();
for (long long i = 0; i < N; ++i) {
long long n = lower_bound(dis.begin(),dis.end(),A[i].second) - dis.begin();
lst.emplace_back(A[i].first,0,n);
lst.emplace_back(A[i].first+mid,1,n);
}
sort(lst.begin(),lst.end());
for (long long i = 0; i <= N; ++i) ft[i] = 0;
long long cnt = 0;
for (auto x: lst) {
long long a,b,c; tie(a,b,c) = x;
if (b == 0) {
long long n = lower_bound(dis.begin(),dis.end(),dis[c]-mid) - dis.begin();
long long m = upper_bound(dis.begin(),dis.end(),dis[c]+mid) - dis.begin() - 1;
cnt += query(m) - query(n-1);
update(c,1);
}
else update(c,-1);
}
if (cnt >= K) high = mid;
else low = mid;
}
lst.clear();
for (long long i = 0; i < N; ++i) {
long long n = lower_bound(dis.begin(),dis.end(),A[i].second) - dis.begin();
lst.emplace_back(A[i].first,0,n);
lst.emplace_back(A[i].first+low,1,n);
}
sort(lst.begin(),lst.end());
for (auto x: lst) {
long long a,b,c; tie(a,b,c) = x;
if (b == 0) {
long long n = lower_bound(dis.begin(),dis.end(),dis[c]-low) - dis.begin();
auto it = s.lower_bound(make_pair(n,-4e18));
while (it != s.end() && abs(dis[it->first]-dis[c]) <= low) {
ans.push_back(max(abs(dis[it->first]-dis[c]),abs(it->second-a)));
it++;
}
s.emplace(c,a);
}
else s.erase(make_pair(c,a-low));
}
sort(ans.begin(),ans.end());
for (long long x: ans) cout << x << '\n';
for (long long i = ans.size(); i < K; ++i) cout << high << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
5048 KB |
Output is correct |
2 |
Correct |
50 ms |
5116 KB |
Output is correct |
3 |
Correct |
44 ms |
5072 KB |
Output is correct |
4 |
Correct |
42 ms |
5216 KB |
Output is correct |
5 |
Correct |
44 ms |
3896 KB |
Output is correct |
6 |
Correct |
8 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3857 ms |
25064 KB |
Output is correct |
2 |
Correct |
3900 ms |
28072 KB |
Output is correct |
3 |
Correct |
45 ms |
5056 KB |
Output is correct |
4 |
Correct |
4011 ms |
27920 KB |
Output is correct |
5 |
Correct |
3949 ms |
28080 KB |
Output is correct |
6 |
Correct |
3773 ms |
28172 KB |
Output is correct |
7 |
Correct |
3792 ms |
27528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5253 ms |
21400 KB |
Output is correct |
2 |
Correct |
5232 ms |
21412 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
3678 ms |
21420 KB |
Output is correct |
5 |
Correct |
3105 ms |
21444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5253 ms |
21400 KB |
Output is correct |
2 |
Correct |
5232 ms |
21412 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
3678 ms |
21420 KB |
Output is correct |
5 |
Correct |
3105 ms |
21444 KB |
Output is correct |
6 |
Correct |
5175 ms |
21352 KB |
Output is correct |
7 |
Correct |
5305 ms |
26396 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
5226 ms |
26480 KB |
Output is correct |
11 |
Correct |
3680 ms |
24256 KB |
Output is correct |
12 |
Correct |
3085 ms |
26724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
5048 KB |
Output is correct |
2 |
Correct |
50 ms |
5116 KB |
Output is correct |
3 |
Correct |
44 ms |
5072 KB |
Output is correct |
4 |
Correct |
42 ms |
5216 KB |
Output is correct |
5 |
Correct |
44 ms |
3896 KB |
Output is correct |
6 |
Correct |
8 ms |
468 KB |
Output is correct |
7 |
Correct |
2023 ms |
16232 KB |
Output is correct |
8 |
Correct |
2023 ms |
16216 KB |
Output is correct |
9 |
Correct |
42 ms |
5216 KB |
Output is correct |
10 |
Correct |
1930 ms |
15460 KB |
Output is correct |
11 |
Correct |
1844 ms |
15324 KB |
Output is correct |
12 |
Correct |
1126 ms |
12960 KB |
Output is correct |
13 |
Correct |
1169 ms |
14784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
5048 KB |
Output is correct |
2 |
Correct |
50 ms |
5116 KB |
Output is correct |
3 |
Correct |
44 ms |
5072 KB |
Output is correct |
4 |
Correct |
42 ms |
5216 KB |
Output is correct |
5 |
Correct |
44 ms |
3896 KB |
Output is correct |
6 |
Correct |
8 ms |
468 KB |
Output is correct |
7 |
Correct |
3857 ms |
25064 KB |
Output is correct |
8 |
Correct |
3900 ms |
28072 KB |
Output is correct |
9 |
Correct |
45 ms |
5056 KB |
Output is correct |
10 |
Correct |
4011 ms |
27920 KB |
Output is correct |
11 |
Correct |
3949 ms |
28080 KB |
Output is correct |
12 |
Correct |
3773 ms |
28172 KB |
Output is correct |
13 |
Correct |
3792 ms |
27528 KB |
Output is correct |
14 |
Correct |
5253 ms |
21400 KB |
Output is correct |
15 |
Correct |
5232 ms |
21412 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
3678 ms |
21420 KB |
Output is correct |
18 |
Correct |
3105 ms |
21444 KB |
Output is correct |
19 |
Correct |
5175 ms |
21352 KB |
Output is correct |
20 |
Correct |
5305 ms |
26396 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
5226 ms |
26480 KB |
Output is correct |
24 |
Correct |
3680 ms |
24256 KB |
Output is correct |
25 |
Correct |
3085 ms |
26724 KB |
Output is correct |
26 |
Correct |
2023 ms |
16232 KB |
Output is correct |
27 |
Correct |
2023 ms |
16216 KB |
Output is correct |
28 |
Correct |
42 ms |
5216 KB |
Output is correct |
29 |
Correct |
1930 ms |
15460 KB |
Output is correct |
30 |
Correct |
1844 ms |
15324 KB |
Output is correct |
31 |
Correct |
1126 ms |
12960 KB |
Output is correct |
32 |
Correct |
1169 ms |
14784 KB |
Output is correct |
33 |
Correct |
5647 ms |
30988 KB |
Output is correct |
34 |
Correct |
5719 ms |
30868 KB |
Output is correct |
35 |
Correct |
5360 ms |
30224 KB |
Output is correct |
36 |
Correct |
3038 ms |
28572 KB |
Output is correct |
37 |
Correct |
3004 ms |
28428 KB |
Output is correct |
38 |
Correct |
3172 ms |
29728 KB |
Output is correct |