匈牙利算法
#include<cstdio> #include<cstring> #include<cctype> #include<algorithm> using namespace std; int n,m,mx,ans,a[2005]; inline int read(){ char ch=getchar();int k=0; while(!isdigit(ch))ch=getchar(); while(isdigit(ch)){k=(k<<1)+(k<<3)+ch-‘0‘;ch=getchar();} return k; } bool check(int h,int w){ int now=w,had=0; while(a[now]>=h) now++; while(now<n+w){ had++; now+=mx; while(a[now]>=h)now++; } if(had<=m)return 1;else return 0; } int main(){ n=read();m=read();mx=read(); int ll=2e9,rr=-2e9,ans=-2e9; for(int i=0;i<n;i++) {a[i]=a[i+n]=read();ll=min(ll,a[i]);rr=max(rr,a[i]);} for(int i=0;i<mx;i++){ int l=ll,r=rr; while(l<=r){ int mid=(l+r)>>1; if(check(mid,i)) l=mid+1;else r=mid-1; } ans=max(ans,r); } printf("%d\n",ans); return 0; }