提交时间:2024-05-25 15:36:23
运行 ID: 149026
#include<bits/stdc++.h> using namespace std; struct book{ int z; int c; int h; }; book a[1145]; int ans; bool cmp(const book &a,const book &b){ return a.z<b.z; } int main(){ int n; int k; cin>>n>>k; for(int i=0;i<n;i++){ cin>>a[i].z>>a[i].h; } sort(a,a+n,cmp); for(int i=0;i<n;i++){ cout<<a[i].h<<" "<<a[i].z<<"\n"; } while(k--){ int lt,id; for(int i=0;i<n;i++){ if(i==0||lt<a[i].c){ lt=a[i].c; id=i; } } for(int i=id;i<n-1;i++){ a[i].c=a[i+1].c; a[i].z=a[i+1].z; } n--; for(int i=0;i<n;i++){ if(i==0){ a[i].c=abs(a[i].z-a[i+1].z); } else if(i==n-1){ a[i].c=abs(a[i].z-a[i-1].z); } else { a[i].c=abs(a[i].z-a[i-1].z)+abs(a[i].z-a[i+1].z); } } } for(int i=0;i<n;i++){ ans+=abs(a[i].z-a[i+1].z); } cout<<ans; return 0; }