提交时间:2023-11-20 13:25:54
运行 ID: 111328
#include<bits/stdc++.h> using namespace std; int main() { int l,n,m,a[100000]; cin>>l>>n>>m; a[0]=0; for(int b=1;b<=n;b++) { cin>>a[b]; a[b]-=a[b-1]; } a[n+1]=l-a[n]; int minn=9999; int d=n+1; int e=0; for(int b=1;b<=m;) { for(int c=1;c<=d;c++) { if(a[c]<minn) { minn=a[c]; e=c; } } if(e!=d) { a[e+1]+=a[e]; for(int f=e+1;f<=d;f++) { a[f-1]=a[f]; } d--; e=0; minn=9999; b++; } else { a[d]+=a[d-1]; a[d-1]=a[d]; d--; e=0; minn=9999; b++; } } int f=0; for(int c=1;c<=d;c++) { if(a[c]<minn) { minn=a[c]; f=c; } } cout<<a[f]; return 0; }