102.愤怒的LJF

2841 愤怒的LJF

 

 时间限制: 1 s
 空间限制: 32000 KB
 题目等级 : 黄金 Gold
题目描述 Description

LJF发现ZPC的积分比他高,他很愤怒。

他挤出T时间做题,他有Q的智慧,他只会做难度系数比他的智慧低或相等的题目。

有N道题,第i道题的时间为Ti,难度系数为Qi,可获积分Wi。

LJF有M积分,ZPC有S积分,求LJF最多积分的情况下是否能超过ZPC。

输入描述 Input Description

第一行:N M T Q S

第二行到第N+1行:Ti Qi Wi

输出描述 Output Description

第一行:YES/NO

第二行:为LJF做题后的分数。

样例输入 Sample Input

2 5 10 40 15

5 20 9

5 30 10

样例输出 Sample Output

YES

24

数据范围及提示 Data Size & Hint

N<=1000

分类标签 Tags 点此展开 

codevs上数据有问题
代码:
#include< cstdio >
#include< iostream >
using namespace std;
int w[1001],tim[1001],f[50001];
int n,m,t,q,s;
void input()
{
scanf("%d%d%d%d%d",&n,&m,&t,&q,&s);
int a,b,c;
int k=0;
for(int i=1;i<=n;++i)
{
scanf("%d%d%d",&a,&b,&c);
if(b>q) continue;
++k;
tim[k]=a;
w[k]=c;
}
n=k;
}
int main()
{
input();
for(int i=1;i<=n;++i)
      for(int j=t;j>=0;--j)
 {
  if(j-tim[i]>=0)
  f[j]=max(f[j],f[j-tim[i]]+w[i]);
}  
if(m+f[t]>s) printf("YES\n");
else printf("NO\n");
printf("%d",m+f[t]);
return 0;
}
posted @ 2016-03-20 10:58  csgc0131123  阅读(159)  评论(0编辑  收藏  举报