题目链接
#include<cstdio>
#include<algorithm>
#include<cstring>
#define N 2005
using namespace std;
int n,q[N],ap,bp,dp[N][N],as,bs,m,w;
int main()
{
scanf("%d%d%d",&n,&m,&w);
memset(dp,,sizeof(dp));
for (int i=;i<=n;i++)
{
scanf("%d%d%d%d",&ap,&bp,&as,&bs);
for (int j=;j<=as;j++) dp[i][j]=-*j*ap;
for (int j=;j<=m;j++) dp[i][j]=max(dp[i][j],dp[i-][j]);
if (i<=w) continue;
int l=,r=;
for (int j=;j<=m;j++)
{
while (l<=r && q[l]<j-as) l++;
while (l<=r && dp[i-w-][q[r]]+q[r]*ap<=dp[i-w-][j]+j*ap) r--;
q[++r]=j;
if (l<=r) dp[i][j]=max(dp[i][j],dp[i-w-][q[l]]+q[l]*ap-j*ap);
}
l=,r=;
for (int j=m;j>=;j--)
{
while (l<=r && q[l]>j+bs) l++;
while (l<=r && dp[i-w-][q[r]]+q[r]*bp<=dp[i-w-][j]+j*bp) r--;
q[++r]=j;
dp[i][j]=max(dp[i][j],dp[i-w-][q[l]]+q[l]*bp-j*bp);
}
}
printf("%d\n",dp[n][]);
return ;
}