#include <bits/stdc++.h>
bool home = 1;
using namespace std;
typedef long long ll;
const int N=250000+7;
struct T{
ll x;
ll y;
int y_norm;
};
bool cmpTx(T a,T b) {
return a.x<b.x;
}
int n;
int k;
T a[N];
vector<ll> ys;
int aib[N];
void clr() {
for(int i=1;i<=n;i++) aib[i]=0;
}
void add(int i,int x) {
while (i<=n) {
aib[i]+=x;
i+=i&(-i);
}
}
int get(ll val) {
int low=0,high=(int)ys.size()-1,i=0,sol=0;
while (low<=high) {
int mid=(low+high)/2;
if(ys[mid]<=val) {
i=mid+1;
low=mid+1;
}else{
high=mid-1;
}
}
while(i) {
sol+=aib[i];
i-=i&(-i);
}
return sol;
}
ll how_many_under(ll d) {
clr();
ll sol=0;
int pt=1;
for (int i=1;i<=n;i++) {
while (a[i].x-a[pt].x>d) add(a[pt++].y_norm,-1);
sol+=get(a[i].y+d)-get(a[i].y-d-1);
add(a[i].y_norm,+1);
}
return sol;
}
signed main() {
#ifdef ONLINE_JUDGE
home = 0;
#endif
home=0;
if (home) {
freopen("I_am_iron_man", "r", stdin);
}
else {
ios::sync_with_stdio(0); cin.tie(0);
}
cin>>n>>k;
for (int i=1;i<=n;i++) {
int x,y;
cin>>x>>y;
a[i].x=x+y;
a[i].y=x-y;
ys.push_back(a[i].y);
}
sort(ys.begin(), ys.end());
ys.resize(unique(ys.begin(),ys.end())-ys.begin());
for (int i=1;i<=n;i++) {
a[i].y_norm=lower_bound(ys.begin(),ys.end(),a[i].y)-ys.begin()+1;
}
sort(a+1,a+n+1,cmpTx);
ll low=0,high=(ll)1e10,sol=-1;
while (low<=high) {
ll mid=(low+high)/2;
if(how_many_under(mid)<=k) {
sol=mid;
low=mid+1;
}else{
high=mid-1;
}
}
assert(n<=1000);
vector<ll> v;
int pt=1;
for (int i=1;i<=n;i++) {
while (a[i].x-a[pt].x>sol) pt++;
for (int j=pt;j<i;j++) {
if(abs(a[i].y-a[j].y)<=sol){
v.push_back(max(a[i].x-a[j].x,abs(a[i].y-a[j].y)));
}
}
}
sort(v.begin(),v.end());
assert((int)v.size()<=k);
v.resize(k, sol+1);
for (auto &x: v) {
cout<<x<<"\n";
}
}
Compilation message
road_construction.cpp: In function 'int main()':
road_construction.cpp:76:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
76 | freopen("I_am_iron_man", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
4932 KB |
Output is correct |
2 |
Correct |
57 ms |
4932 KB |
Output is correct |
3 |
Correct |
38 ms |
5060 KB |
Output is correct |
4 |
Correct |
40 ms |
5148 KB |
Output is correct |
5 |
Correct |
42 ms |
3880 KB |
Output is correct |
6 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1516 ms |
18600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2949 ms |
18604 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2949 ms |
18604 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
4932 KB |
Output is correct |
2 |
Correct |
57 ms |
4932 KB |
Output is correct |
3 |
Correct |
38 ms |
5060 KB |
Output is correct |
4 |
Correct |
40 ms |
5148 KB |
Output is correct |
5 |
Correct |
42 ms |
3880 KB |
Output is correct |
6 |
Correct |
3 ms |
340 KB |
Output is correct |
7 |
Runtime error |
1096 ms |
7828 KB |
Execution killed with signal 6 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
4932 KB |
Output is correct |
2 |
Correct |
57 ms |
4932 KB |
Output is correct |
3 |
Correct |
38 ms |
5060 KB |
Output is correct |
4 |
Correct |
40 ms |
5148 KB |
Output is correct |
5 |
Correct |
42 ms |
3880 KB |
Output is correct |
6 |
Correct |
3 ms |
340 KB |
Output is correct |
7 |
Runtime error |
1516 ms |
18600 KB |
Execution killed with signal 6 |
8 |
Halted |
0 ms |
0 KB |
- |