#include <bits/stdc++.h>
using namespace std;
struct pont{
int x,y;
int s;
};
struct par{
int a,b;
};
struct classcomp1{
bool operator() (pont x,pont y) {
return((x.x<y.x)||((x.x==y.x)&&(x.s<y.s)));
}
};
struct classcomp2{
bool operator() (pont x,pont y) {
return((x.y<y.y)||((x.y==y.y)&&(x.s<y.s)));
}
};
bool kis(pont x,pont y) {
return((x.y<y.y)||((x.y==y.y)&&(x.x<y.x)));
};
int n,k;
int x,y;
vector<pont> t;
vector<pont> orig;
vector<pont> t2;
pont z;
vector<par> cur,ma;
par q;
set<pont,classcomp1> s1;
set<pont,classcomp1>::iterator it1;
set<pont,classcomp2> s2;
set<pont,classcomp2>::iterator it2;
int db;
bool exist(int d) {
cur.clear(); s1.clear(); s2.clear();
for (pont i:t2) {
//cout << d << " " << i.s << endl;
db=0;
while ((s2.size()>0)&&((*s2.begin()).y<i.y-d)) {
//cout << d << " " << i.s << " erase: " << (*s2.begin()).s << endl;
s1.erase((*s2.begin()));
s2.erase(s2.begin());
db++;
if (db>10000) {
cout << "err" << endl;
return(true);
}
}
z=i; z.x-=d; z.s=-1;
for (it1=s1.lower_bound(z);(it1!=s1.end())&&((*it1).x<=i.x+d);it1++) {
//cout << d << " " << i.s << " found: " << (*it1).s << endl;
q.a=i.s; q.b=(*it1).s;
cur.push_back(q);
if (cur.size()>=k) {
//cout << d << " true" << endl;
return(true);
}
}
s1.insert(i);
s2.insert(i);
}
//cout << d << " false" << endl;
return(false);
}
int log_search(int l,int r) {
//cout << l << " " << r << endl;
if (l>=r) {
return(l);
}
if (exist((l+r)/2+1)) {
ma=cur;
return(log_search(l,(l+r)/2));
} else {
return(log_search((l+r)/2+1,r));
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
for (int i=0;i<n;i++) {
cin >> x >> y;
z.x=x+y; z.y=x-y; z.s=i;
t.push_back(z);
z.x=x; z.y=y; z.s=i;
orig.push_back(z);
}
t2=t;
sort(t2.begin(),t2.end(),kis);
int ans=log_search(1,2e9);
exist(ans);
vector<int> lengths; lengths.clear();
for (par i:cur) {
lengths.push_back(abs(orig[i.a].x-orig[i.b].x)+abs(orig[i.a].y-orig[i.b].y));
}
//cout << lengths.size() << endl;
for (;lengths.size()<k;) {
lengths.push_back(ans+1);
}
sort(lengths.begin(),lengths.end());
for (int i:lengths) {
cout << i << endl;
}
return 0;
}
/*
3 2
-1 0
0 2
0 0
*/
/*
5 4
1 -1
2 0
-1 0
0 2
0 -2
*/
Compilation message
road_construction.cpp: In function 'bool exist(int)':
road_construction.cpp:66:27: warning: comparison of integer expressions of different signedness: 'std::vector<par>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
66 | if (cur.size()>=k) {
| ~~~~~~~~~~^~~
road_construction.cpp: In function 'int main()':
road_construction.cpp:112:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
112 | for (;lengths.size()<k;) {
| ~~~~~~~~~~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
10094 ms |
2504 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
861 ms |
17232 KB |
Output is correct |
2 |
Correct |
902 ms |
17072 KB |
Output is correct |
3 |
Execution timed out |
10100 ms |
2504 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
279 ms |
9248 KB |
Output is correct |
2 |
Correct |
437 ms |
9304 KB |
Output is correct |
3 |
Execution timed out |
10030 ms |
212 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
279 ms |
9248 KB |
Output is correct |
2 |
Correct |
437 ms |
9304 KB |
Output is correct |
3 |
Execution timed out |
10030 ms |
212 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
10094 ms |
2504 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
10094 ms |
2504 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |