#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("VNOICUP.INP");
ofstream fout("VNOICUP.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
using u128 = __uint128_t;
//const int x[4] = {1, -1, 0, 0};
//const int y[4] = {0, 0, 1, -1};
const ll mod = 998244353;
const int mxn = 25e4 + 5, mxq = 2e5 + 5, sq = 400, mxv = 2e7 + 5;
//const int base = (1 << 18);
const ll inf = 1e9 + 5, neg = -69420;
int n, k;
pll p[mxn + 1];
bool ck(ll mid){
multiset<ll>ms;
int l = 1, cnt = 0;
for(int i = 1; i <= n; i++){
while(p[i].fi - p[l].fi > mid){
ms.erase(ms.find(p[l].se)); l++;
}
auto it = ms.lower_bound(p[i].se - mid);
for(;it != ms.end(); ++it){
if((*it) > p[i].se + mid)break;
cnt++;
if(cnt > k)return(0);
}
ms.insert(p[i].se);
}
return(1);
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> k;
for(int i = 1; i <= n; i++){
int x, y; cin >> x >> y;
p[i] = make_pair(x + y, x - y);
}
sort(p + 1, p + n + 1);
ll l = 0, r = 4e9, ans;
while(l <= r){
ll mid = (l + r) >> 1;
if(ck(mid)){
ans = mid; l = mid + 1;
}else{
r = mid - 1;
}
}
set<pair<ll, ll>>s;
vt<ll>res;
int lp = 1;
for(int i = 1; i <= n; i++){
while(p[i].fi - p[lp].fi > ans){
s.erase(make_pair(p[lp].se, p[lp].fi)); lp++;
}
auto it = s.lower_bound(make_pair(p[i].se - ans, -inf));
for(;it != s.end(); ++it){
cout << "aa";
auto [candy, candx] = (*it);
ll dist = max(p[i].fi - candx, abs(p[i].se - candy));
if(dist <= ans){
res.pb(dist);
}else{
break;
}
}
s.insert(make_pair(p[i].se, p[i].fi));
}
sort(res.begin(), res.end());
for(auto i: res)cout << i << "\n";
forr(i, 0, k - sz(res)){
cout << ans + 1 << "\n";
}
return(0);
}
Compilation message
road_construction.cpp: In function 'int main()':
road_construction.cpp:74:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
74 | auto [candy, candx] = (*it);
| ^
road_construction.cpp:89:23: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
89 | cout << ans + 1 << "\n";
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
83 ms |
5468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
259 ms |
8040 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
244 ms |
4356 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
244 ms |
4356 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
83 ms |
5468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
83 ms |
5468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |