#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("avx2")
using namespace std;
using namespace __gnu_pbds;
#define fi first
#define se second
#define all(m) (m).begin(), (m).end()
#define rall(m) (m).rbegin(), (m).rend()
#define vec vector
#define sz(a) (int) (a).size()
#define mpp make_pair
#define mtt make_tuple
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tui;
template <typename T>
using prq = priority_queue <T>;
template <typename T>
using pgq = priority_queue <T, vec <T>, greater <T>>;
template <typename T> bool umin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template <typename T> bool umax(T &a, T b) { return a < b ? a = b, 1 : 0; }
inline int solve(){
int n, k;
cin >> n >> k;
vec <pii> a(n);
for (int i = 0; i < n; ++i){
int x, y;
cin >> x >> y;
a[i] = {x + y, x - y};
}
sort(all(a));
vec <ll> res;
auto work = [&](ll d, bool fl){
vec <ll> ans;
set <pll> s;
for (int r = 0, l = 0; r < n; ++r){
while(a[l].fi + d < a[r].fi){
s.erase({a[l].se, a[l].fi}), ++l;
}
auto [x, y] = a[r];
auto it = s.lower_bound({y - d, -3e9});
while(sz(ans) < k){
if (it == s.end()) break;
auto [cy, cx] = *it;
if (y + d < cy) break;
ans.push_back(max(abs(x - cx), abs(y - cy)));
++it;
}
s.insert({a[r].se, a[r].fi});
}
if (fl){
while(sz(ans) < k){
ans.push_back(d + 1);
}
res = ans;
}
return sz(ans) >= k;
};
ll len = 0;
for (int i = 31; ~i; --i){
len += 1LL << i;
if (work(len, 0)){
len -= 1LL << i;
}
}
work(len, 1);
sort(all(res));
for (auto &i: res){
cout << i << "\n";
}
return 0;
}
inline void precalc(){}
signed main(){
// ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int tst = 1; //cin >> tst;
precalc();
while(tst--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
6812 KB |
Output is correct |
2 |
Correct |
135 ms |
6876 KB |
Output is correct |
3 |
Correct |
111 ms |
6972 KB |
Output is correct |
4 |
Correct |
112 ms |
7012 KB |
Output is correct |
5 |
Correct |
114 ms |
5668 KB |
Output is correct |
6 |
Correct |
4 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
923 ms |
19768 KB |
Output is correct |
2 |
Correct |
923 ms |
19780 KB |
Output is correct |
3 |
Correct |
83 ms |
8708 KB |
Output is correct |
4 |
Correct |
869 ms |
19780 KB |
Output is correct |
5 |
Correct |
1022 ms |
21492 KB |
Output is correct |
6 |
Correct |
938 ms |
21496 KB |
Output is correct |
7 |
Correct |
924 ms |
20348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1825 ms |
14828 KB |
Output is correct |
2 |
Correct |
1852 ms |
19524 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
812 ms |
20684 KB |
Output is correct |
5 |
Correct |
1808 ms |
23232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1825 ms |
14828 KB |
Output is correct |
2 |
Correct |
1852 ms |
19524 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
812 ms |
20684 KB |
Output is correct |
5 |
Correct |
1808 ms |
23232 KB |
Output is correct |
6 |
Correct |
1959 ms |
19516 KB |
Output is correct |
7 |
Correct |
1865 ms |
19656 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
9 |
Correct |
0 ms |
304 KB |
Output is correct |
10 |
Correct |
1897 ms |
19628 KB |
Output is correct |
11 |
Correct |
889 ms |
20812 KB |
Output is correct |
12 |
Correct |
1754 ms |
23116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
6812 KB |
Output is correct |
2 |
Correct |
135 ms |
6876 KB |
Output is correct |
3 |
Correct |
111 ms |
6972 KB |
Output is correct |
4 |
Correct |
112 ms |
7012 KB |
Output is correct |
5 |
Correct |
114 ms |
5668 KB |
Output is correct |
6 |
Correct |
4 ms |
340 KB |
Output is correct |
7 |
Correct |
1112 ms |
10256 KB |
Output is correct |
8 |
Correct |
1085 ms |
12228 KB |
Output is correct |
9 |
Correct |
109 ms |
6936 KB |
Output is correct |
10 |
Correct |
823 ms |
10004 KB |
Output is correct |
11 |
Correct |
657 ms |
10020 KB |
Output is correct |
12 |
Correct |
562 ms |
13072 KB |
Output is correct |
13 |
Correct |
764 ms |
11424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
6812 KB |
Output is correct |
2 |
Correct |
135 ms |
6876 KB |
Output is correct |
3 |
Correct |
111 ms |
6972 KB |
Output is correct |
4 |
Correct |
112 ms |
7012 KB |
Output is correct |
5 |
Correct |
114 ms |
5668 KB |
Output is correct |
6 |
Correct |
4 ms |
340 KB |
Output is correct |
7 |
Correct |
923 ms |
19768 KB |
Output is correct |
8 |
Correct |
923 ms |
19780 KB |
Output is correct |
9 |
Correct |
83 ms |
8708 KB |
Output is correct |
10 |
Correct |
869 ms |
19780 KB |
Output is correct |
11 |
Correct |
1022 ms |
21492 KB |
Output is correct |
12 |
Correct |
938 ms |
21496 KB |
Output is correct |
13 |
Correct |
924 ms |
20348 KB |
Output is correct |
14 |
Correct |
1825 ms |
14828 KB |
Output is correct |
15 |
Correct |
1852 ms |
19524 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
812 ms |
20684 KB |
Output is correct |
18 |
Correct |
1808 ms |
23232 KB |
Output is correct |
19 |
Correct |
1959 ms |
19516 KB |
Output is correct |
20 |
Correct |
1865 ms |
19656 KB |
Output is correct |
21 |
Correct |
1 ms |
300 KB |
Output is correct |
22 |
Correct |
0 ms |
304 KB |
Output is correct |
23 |
Correct |
1897 ms |
19628 KB |
Output is correct |
24 |
Correct |
889 ms |
20812 KB |
Output is correct |
25 |
Correct |
1754 ms |
23116 KB |
Output is correct |
26 |
Correct |
1112 ms |
10256 KB |
Output is correct |
27 |
Correct |
1085 ms |
12228 KB |
Output is correct |
28 |
Correct |
109 ms |
6936 KB |
Output is correct |
29 |
Correct |
823 ms |
10004 KB |
Output is correct |
30 |
Correct |
657 ms |
10020 KB |
Output is correct |
31 |
Correct |
562 ms |
13072 KB |
Output is correct |
32 |
Correct |
764 ms |
11424 KB |
Output is correct |
33 |
Correct |
2744 ms |
21500 KB |
Output is correct |
34 |
Correct |
2703 ms |
21560 KB |
Output is correct |
35 |
Correct |
2156 ms |
21544 KB |
Output is correct |
36 |
Correct |
1448 ms |
27004 KB |
Output is correct |
37 |
Correct |
1427 ms |
24936 KB |
Output is correct |
38 |
Correct |
1790 ms |
25112 KB |
Output is correct |