#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
#define int ll
using namespace std;
using ll = long long;
const ll N = 2e5+5 , inf = 2e9 + 7;
const ll INF = 1e18 , mod = 1e9+7;
int x[N] , y[N] , ord[N] , nxt[N];
int n , k;
int get(int i , int j){
return abs(x[i]-x[j]) + abs(y[i]-y[j]);
}
void slow(){
vector<pair<int,int>> v;
for(int i = 1; i <= n; i++){
for(int j = i+1; j <= n; j++){
v.push_back({i,j});
}
}
sort(all(v),[&](pair<int,int> i , pair<int,int> j){
return (get(i.F , i.S) < get(j.F , j.S));
});
for(int i = 0; i < k; i++){
cout << get(v[i].F,v[i].S) << "\n";
}
}
void k_one(){
for(int i = 1; i <= n; i++){
ord[i] = i;
}
sort(ord+1,ord+1+n,[&](int i , int j){
if(x[i] == x[j]) return y[i] < y[j];
return x[i] < x[j];
});
for(int i = 1; i <= n; i++){
}
}
void only_x(){
sort(x+1,x+1+n);
set<pair<int,int>> st;
for(int i = 1; i <= n; i++){
nxt[i] = i+1;
if(nxt[i] <= n){
st.insert({x[nxt[i]]-x[i] , i});
}
}
while(k--){
int i = st.begin()->S;
st.erase(st.begin());
cout << x[nxt[i]] - x[i] <<"\n";
nxt[i]++;
if(nxt[i] <= n) st.insert({x[nxt[i]]-x[i] , i});
}
}
void solve(){
cin >> n >> k;
int cnt = 0;
for(int i = 1; i <= n; i++){
cin >> x[i] >> y[i];
if(y[i] == 0){
cnt++;
}
}
if(cnt == n){
only_x();
} else if(k == 1){
k_one();
} else {
slow();
}
}
/*
*/
signed main(){
ios;
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |