// made by Tima
// 2025 will be a golden year...
//BREAK YOUR LIMITS!!!!
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define int long long
#define y1 SBIL
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define pii pair<int,int>
#define tpii pair <pair <int,int> , int>
using namespace std;
using namespace __gnu_pbds;
const int N = 3e5 + 5;
int mod = 1e9 + 7;
const int INF = 1e18;
int n,k,a[N],b[N],d = 1e9;
pii p[N];
pii nigger;
map <pii,int> mp;
int dist(int x1 , int y1 , int x2 , int y2){
return abs(x1 - x2) + abs(y1 - y2);
}
void solve(int l , int r){
if(l == r) return;
int md = l + r >> 1;
solve(l , md) , solve(md + 1 , r);
for(int i = md - 1 ; i >= 1 ; i--){
if(abs(a[i] - a[md]) >= d) break;
if(!mp[{md , i}] && d > dist(a[i] , b[i] , a[md] , b[md])){
d = dist(a[i] , b[i] , a[md] , b[md]);
// cout << md << ' ' << i << ' ' << dist(a[i] , b[i] , a[md] , b[md]) << '\n';
nigger = {md , i};
}
}
for(int i = md + 1 ; i <= n ; i++){
if(abs(a[i] - a[md]) >= d) break;
if(!mp[{md , i}] && d > dist(a[i] , b[i] , a[md] , b[md])){
d = dist(a[i] , b[i] , a[md] , b[md]);
// cout << md << ' ' << i << ' ' << dist(a[i] , b[i] , a[md] , b[md]) << '\n';
nigger = {md , i};
}
}
}
void Gold(){
cin >> n >> k;
bool ok = 1;
for(int i = 1 ; i <= n ; i++){
cin >> a[i] >> b[i];
p[i] = {a[i] , b[i]};
if(b[i] != 0) ok = 0;
}
sort(p + 1 , p + n + 1);
for(int i = 1 ; i <= n ; i++){
a[i] = p[i].F , b[i] = p[i].S;
}
if(n <= 1000){
multiset <int> q;
for(int i = 1 ; i <= n ; i++){
for(int j = i + 1 ; j <= n ; j++){
// cout << abs(a[i] - a[j]) + abs(b[i] - b[j]) << ' ' << i << ' ' << j << '\n';
q.insert(abs(a[i] - a[j]) + abs(b[i] - b[j]));
}
}
int cnt = 0;
for(auto it : q){
cout << it << '\n';
cnt++;
if(cnt == k){
break;
}
}
return;
}
//2 4
//4 5
if(k == 1){
solve(1 , n);
cout << d << '\n';
return;
}
while(k--){
d = 1e9;
solve(1 , n);
cout << d << '\n';
// cout << nigger.F << ' ' << nigger.S << '\n';
mp[nigger] = 1;
mp[{nigger.S , nigger.F}] = 1;
}
}
signed main(/*Zhunussov Temirlan*/){
//freopen("txt.in","r",stdin);freopen("txt.out","w",stdout);
ios_base::sync_with_stdio(0);cin.tie(0);
srand(time(0));
int TT = 1;
// cin >> TT;
for(int i = 1 ; i <= TT ; i++){
//cout << "Case " << i << ": ";
Gold();
}
}
# | 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... |