提交时间:2024-06-23 18:45:39
运行 ID: 30350
#include<bits/stdc++.h> #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) #define p_b push_back #define pi pair<int,int> #define p1 first #define p2 second #define m_p make_pair using namespace std; typedef long long ll; const int maxn=6e5+10; inline ll read(){ ll x=0;short t=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; } int n,k; struct node { int x,y; }d[maxn]; ll calc(int px,int py){ vector<ll>S; up(i,1,n)S.p_b((ll)abs(px-d[i].x)+(ll)abs(py-d[i].y)); sort(S.begin(),S.end());ll res=0; up(i,0,k-1)res+=S[i]; return res; } void slv(){ n=read(),k=read(); up(i,1,n)d[i].x=read(),d[i].y=read(); ll res=1e18; up(i,1,n)up(j,1,n)res=min(res,calc(d[i].x,d[j].y)); cout<<res; }int main(){ // freopen("dating.in","r",stdin); // freopen("dating.out","w",stdout); slv(); fclose(stdin); fclose(stdout); //cerr<<clock()*1.0/CLOCKS_PER_SEC<<"s\n"; return 0; }