#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ull unsigned ll
#define pb push_back
#define epb emplace_back
using namespace std;
struct Point{
ll x,y;
Point(ll x,ll y):x(x),y(y){}
Point(){
}
};
ll dist(Point A,Point B){
return abs(A.x-B.x)+abs(A.y-B.y);
}
bool check(vector<Point>a){
for(Point A:a){
if(A.y!=0)return false;
}
return true;
}
bool comp(Point A,Point B){
if(A.x==B.x)return A.y<B.y;
return A.x<B.x;
}
void solve(){
int n;cin>>n;
int k;cin>>k;
vector<Point>a(n);
for(int i=0;i<n;i++)cin>>a[i].x>>a[i].y;
sort(a.begin(),a.end(),comp);
if(check(a)){
vector<ll>vec;
for(int i=0;i<n;i++)vec.pb(a[i].x);
int l=0,r=1e15;
while(l+1<r){
ll mid=(l+r)/2;
ll ans=0;
for(int i=0;i<vec.size();i++){
int x=upper_bound(vec.begin(),vec.end(),vec[i]+mid)-vec.begin();
ans+=x-i-1;
if(ans>=k)break;
}
if(ans>=k)r=mid;
else l=mid;
}
multiset<ll>d;
for(int i=0;i<n;i++){
for(int j=i+1;j<n&&vec[j]<=vec[i]+r;j++)d.insert(dist(a[j],a[i]));
}
int ind=0;
for(ll to:d){
if(ind>=k)break;
cout<<to<<"\n";
ind++;
}
return;
}
multiset<ll>d;
for(int i=0;i<n;i++){
for(int j=0;j<i;j++){
d.insert(dist(a[i],a[j]));
}
}
int ind=0;
for(ll to:d){
if(ind>=k)break;
cout<<to<<"\n";
ind++;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
}
Compilation message
road_construction.cpp: In function 'void solve()':
road_construction.cpp:42:19: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+15' to '2147483647' [-Woverflow]
42 | int l=0,r=1e15;
| ^~~~
road_construction.cpp:46:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i=0;i<vec.size();i++){
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
412 ms |
26416 KB |
Output is correct |
2 |
Correct |
422 ms |
26436 KB |
Output is correct |
3 |
Correct |
180 ms |
14724 KB |
Output is correct |
4 |
Correct |
167 ms |
14728 KB |
Output is correct |
5 |
Correct |
307 ms |
25156 KB |
Output is correct |
6 |
Correct |
174 ms |
23776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
499 ms |
19436 KB |
Output is correct |
2 |
Correct |
510 ms |
22148 KB |
Output is correct |
3 |
Execution timed out |
10065 ms |
332 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
10090 ms |
351332 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
10090 ms |
351332 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
412 ms |
26416 KB |
Output is correct |
2 |
Correct |
422 ms |
26436 KB |
Output is correct |
3 |
Correct |
180 ms |
14724 KB |
Output is correct |
4 |
Correct |
167 ms |
14728 KB |
Output is correct |
5 |
Correct |
307 ms |
25156 KB |
Output is correct |
6 |
Correct |
174 ms |
23776 KB |
Output is correct |
7 |
Execution timed out |
10039 ms |
346376 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
412 ms |
26416 KB |
Output is correct |
2 |
Correct |
422 ms |
26436 KB |
Output is correct |
3 |
Correct |
180 ms |
14724 KB |
Output is correct |
4 |
Correct |
167 ms |
14728 KB |
Output is correct |
5 |
Correct |
307 ms |
25156 KB |
Output is correct |
6 |
Correct |
174 ms |
23776 KB |
Output is correct |
7 |
Correct |
499 ms |
19436 KB |
Output is correct |
8 |
Correct |
510 ms |
22148 KB |
Output is correct |
9 |
Execution timed out |
10065 ms |
332 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |