题面
https://www.luogu.org/problem/P1987
题解
// luogu-judger-enable-o2 #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> struct tree { long long m,b; bool operator < (const tree rhs) const { return b<rhs.b; } } a[1050]; long long n,yourk,f[1050]; using namespace std; const long long INF=1e8; int main(){ long long i,j,v; while (true) { scanf("%lld %lld",&n,&yourk); if (n==0 && yourk==0) return 0; for (i=1;i<=n;i++) scanf("%lld",&a[i].m); for (i=1;i<=n;i++) scanf("%lld",&a[i].b); sort(a+1,a+n+1); memset(f,0,sizeof(f)); f[0]=0; for (i=n;i>=1;i--) for (j=yourk;j;j--) { v=a[i].m-(j-1)*a[i].b; if (v<0) v=0; if (f[j-1]+v>f[j]) f[j]=f[j-1]+v; } long long ans=0; for (i=1;i<=yourk;i++) if (f[i]>ans) ans=f[i]; cout<<ans<<endl; } }