CF
1000 ms 65536 KiBDescription
LYD loves codeforces since there are many Russian contests. In an contest lasting for T minutes there are n problems, and for the ith problem you can get ai−di∗ti points, where ai indicates the initial points, di indicates the points decreased per minute (count from the beginning of the contest), and ti stands for the passed minutes when you solved the problem (count from the begining of the contest).
Now you know LYD can solve the ith problem in ci minutes. He can't perform as a multi-core processor, so he can think of only one problem at a moment. Can you help him get as many points as he can?
Input
The first line contains two integers n,T(0≤n≤2000,0≤T≤5000).
The second line contains n integers a1,a2,..,an(0<ai≤6000).
The third line contains n integers d1,d2,..,dn(0<di≤50).
The forth line contains n integers c1,c2,..,cn(0<ci≤400).
Output
Output an integer in a single line, indicating the maximum points LYD can get.
Sample
Input
Copy3 10
100 200 250
5 6 7
2 4 10
Output
Copy254
题意:在最后剩下t时间的时候有n道题需要你解决,每道题解决的得分为ai-di*t,解决第i道题需要ti的时间,求解最终所能得到的最大得分为多少。
题解:首先,若只考虑单位时间的扣分,那一定是先做扣分多的,若只考虑时间,则因为先做耗时少的,综合考虑,可将di/ci排序,建立dp数组,dp[j]表示拿第j个单位时间时能获得的最大点数,dp[j]=max(dp[j],dp[j-p[i].c]+p[i].a-p[i].d*j),01背包装一下就可以了。
#include<stdio.h>
#include <algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<algorithm>
#define ll long long
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
using namespace std;
struct node
{
int a,d,c;
double f;
}p[2005];
int cmp(node a,node b)
{
return a.f>b.f;
}
int dp[5005];
int main()
{
int n,t;
cin>>n>>t;
for(int i=1;i<=n;i++)
cin>>p[i].a;
for(int i=1;i<=n;i++)
cin>>p[i].d;
for(int i=1;i<=n;i++)
{
cin>>p[i].c;
p[i].f=p[i].d*1.0/p[i].c;
}
sort(p+1,p+1+n,cmp);
int maxl=0;
for(int i=1;i<=n;i++)
for(int j=t;j>=p[i].c;j--)
{
dp[j]=max(dp[j],dp[j-p[i].c]+p[i].a-p[i].d*j);
maxl=max(maxl,dp[j]);
}
cout<<maxl<<endl;
return 0;
}