#include <bits/stdc++.h>
using namespace std;
#define int long long int
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;
bool exist(int d) {
cur.clear(); s1.clear(); s2.clear();
for (pont i:t2) {
//cout << d << " " << i.s << endl;
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());
}
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)) {
return(log_search(l,(l+r)/2));
} else {
return(log_search((l+r)/2+1,r));
}
}
signed 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,5e9);
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(long long int)':
road_construction.cpp:59:27: warning: comparison of integer expressions of different signedness: 'std::vector<par>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
59 | if (cur.size()>=k) {
| ~~~~~~~~~~^~~
road_construction.cpp: In function 'int main()':
road_construction.cpp:104:25: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
104 | for (;lengths.size()<k;) {
| ~~~~~~~~~~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
413 ms |
10992 KB |
Output is correct |
2 |
Correct |
418 ms |
11008 KB |
Output is correct |
3 |
Correct |
399 ms |
10968 KB |
Output is correct |
4 |
Correct |
432 ms |
11092 KB |
Output is correct |
5 |
Correct |
395 ms |
9704 KB |
Output is correct |
6 |
Correct |
9 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
827 ms |
27520 KB |
Output is correct |
2 |
Correct |
866 ms |
27496 KB |
Output is correct |
3 |
Correct |
393 ms |
10916 KB |
Output is correct |
4 |
Correct |
727 ms |
27228 KB |
Output is correct |
5 |
Correct |
695 ms |
27456 KB |
Output is correct |
6 |
Correct |
693 ms |
27456 KB |
Output is correct |
7 |
Correct |
697 ms |
26668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
300 ms |
18240 KB |
Output is correct |
2 |
Correct |
446 ms |
18316 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
198 ms |
20964 KB |
Output is correct |
5 |
Correct |
1202 ms |
23388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
300 ms |
18240 KB |
Output is correct |
2 |
Correct |
446 ms |
18316 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
198 ms |
20964 KB |
Output is correct |
5 |
Correct |
1202 ms |
23388 KB |
Output is correct |
6 |
Correct |
686 ms |
23140 KB |
Output is correct |
7 |
Correct |
681 ms |
23136 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
657 ms |
23144 KB |
Output is correct |
11 |
Correct |
216 ms |
20996 KB |
Output is correct |
12 |
Correct |
1258 ms |
23384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
413 ms |
10992 KB |
Output is correct |
2 |
Correct |
418 ms |
11008 KB |
Output is correct |
3 |
Correct |
399 ms |
10968 KB |
Output is correct |
4 |
Correct |
432 ms |
11092 KB |
Output is correct |
5 |
Correct |
395 ms |
9704 KB |
Output is correct |
6 |
Correct |
9 ms |
468 KB |
Output is correct |
7 |
Correct |
1508 ms |
19352 KB |
Output is correct |
8 |
Correct |
1444 ms |
19364 KB |
Output is correct |
9 |
Correct |
408 ms |
11096 KB |
Output is correct |
10 |
Correct |
1041 ms |
18636 KB |
Output is correct |
11 |
Correct |
608 ms |
18452 KB |
Output is correct |
12 |
Correct |
1151 ms |
19588 KB |
Output is correct |
13 |
Correct |
959 ms |
17992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
413 ms |
10992 KB |
Output is correct |
2 |
Correct |
418 ms |
11008 KB |
Output is correct |
3 |
Correct |
399 ms |
10968 KB |
Output is correct |
4 |
Correct |
432 ms |
11092 KB |
Output is correct |
5 |
Correct |
395 ms |
9704 KB |
Output is correct |
6 |
Correct |
9 ms |
468 KB |
Output is correct |
7 |
Correct |
827 ms |
27520 KB |
Output is correct |
8 |
Correct |
866 ms |
27496 KB |
Output is correct |
9 |
Correct |
393 ms |
10916 KB |
Output is correct |
10 |
Correct |
727 ms |
27228 KB |
Output is correct |
11 |
Correct |
695 ms |
27456 KB |
Output is correct |
12 |
Correct |
693 ms |
27456 KB |
Output is correct |
13 |
Correct |
697 ms |
26668 KB |
Output is correct |
14 |
Correct |
300 ms |
18240 KB |
Output is correct |
15 |
Correct |
446 ms |
18316 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
198 ms |
20964 KB |
Output is correct |
18 |
Correct |
1202 ms |
23388 KB |
Output is correct |
19 |
Correct |
686 ms |
23140 KB |
Output is correct |
20 |
Correct |
681 ms |
23136 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
657 ms |
23144 KB |
Output is correct |
24 |
Correct |
216 ms |
20996 KB |
Output is correct |
25 |
Correct |
1258 ms |
23384 KB |
Output is correct |
26 |
Correct |
1508 ms |
19352 KB |
Output is correct |
27 |
Correct |
1444 ms |
19364 KB |
Output is correct |
28 |
Correct |
408 ms |
11096 KB |
Output is correct |
29 |
Correct |
1041 ms |
18636 KB |
Output is correct |
30 |
Correct |
608 ms |
18452 KB |
Output is correct |
31 |
Correct |
1151 ms |
19588 KB |
Output is correct |
32 |
Correct |
959 ms |
17992 KB |
Output is correct |
33 |
Correct |
2878 ms |
32952 KB |
Output is correct |
34 |
Correct |
2814 ms |
32960 KB |
Output is correct |
35 |
Correct |
1776 ms |
32308 KB |
Output is correct |
36 |
Correct |
1941 ms |
33508 KB |
Output is correct |
37 |
Correct |
1840 ms |
33364 KB |
Output is correct |
38 |
Correct |
1780 ms |
31720 KB |
Output is correct |