G - Animals

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

input

input.txt

output

output.txt

Once upon a time DravDe, an outstanding person famous for his professional achievements (as you must remember, he works in a warehouse storing Ogudar-Olok, a magical but non-alcoholic drink) came home after a hard day. That day he had to drink 9875 boxes of the drink and, having come home, he went to bed at once.

DravDe dreamt about managing a successful farm. He dreamt that every day one animal came to him and asked him to let it settle there. However, DravDe, being unimaginably kind, could send the animal away and it went, rejected. There were exactly n days in DravDe’s dream and the animal that came on the i-th day, ate exactly ci tons of food daily starting from day i. But if one day the animal could not get the food it needed, it got really sad. At the very beginning of the dream there were exactly X tons of food on the farm.

DravDe woke up terrified...

When he retold the dream to you, he couldn’t remember how many animals were on the farm by the end of the n-th day any more, but he did remember that nobody got sad (as it was a happy farm) and that there was the maximum possible amount of the animals. That’s the number he wants you to find out.

It should be noticed that the animals arrived in the morning and DravDe only started to feed them in the afternoon, so that if an animal willing to join them is rejected, it can’t eat any farm food. But if the animal does join the farm, it eats daily from that day to the n-th.

Input

The first input line contains integers n and X (1 ≤ n ≤ 100, 1 ≤ X ≤ 104) — amount of days in DravDe’s dream and the total amount of food (in tons) that was there initially. The second line contains integers ci (1 ≤ ci ≤ 300). Numbers in the second line are divided by a space.

Output

Output the only number — the maximum possible amount of animals on the farm by the end of the n-th day given that the food was enough for everybody.

Sample Input

Input
3 4
1 1 1
Output
2
Input
3 6
1 1 1
Output
3

Hint

Note to the first example: DravDe leaves the second and the third animal on the farm. The second animal will eat one ton of food on the second day and one ton on the third day. The third animal will eat one ton of food on the third day.

#include<iostream>
#include<cstdio>
#include<fstream>
using namespace std; int ani[];
int dp[];
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int n,x;
cin>>n>>x;
//scanf("%d%d",&n,&x);
for(int i=; i<=n; i++)
{
scanf("%d",&ani[i]);
ani[i]*=(n-i+);
}
for(int i=;i<=n;i++)
for(int j=x;j>=ani[i];j--)
dp[j]=max(dp[j],dp[j-ani[i]]+);
//printf("%d\n",dp[x]);
cout<<dp[x]<<endl;
return ;
}

这道题可以dp,也可以贪心。贪心的想法比较简单。按照消耗从小到大排序,从小的开始拿就可以了。

dp的思想是:

dp[x]=max(dp[x],dp[x-ani[i]+1];

dp[x]表示粮食为x时,最多可以收留的动物数。

最新文章

  1. APP支付报错ALI40247处理方案!
  2. hdu3264Open-air shopping malls(二分)
  3. ios 复制黏贴板的使用
  4. POST多个参数到Web API控制器
  5. VMware vCenter Converter 使用,Error code: 2147549183 (0x8000FFFF) 解决方案
  6. stm32之中断系统
  7. Linux中jdk的安装和环境变量的配置
  8. leetcode — word-ladder
  9. Ubuntu中创建、删除、更改、移动文件的命令
  10. libevent学习笔记 一、基础知识【转】
  11. Hibernate的核心接口
  12. C. Trailing Loves (or L&#39;oeufs?)
  13. Django---Mysql数据库链接
  14. erl_0019《硝烟中的erlang》 读书笔记005 “进程信息&quot;
  15. 同时安装Python2和Python3,如何兼容并切换使用详解
  16. 面对IBM与亚马逊的犄角攻势,微软云如何招架?
  17. Codeforces gym102058 J. Rising Sun-简单的计算几何+二分 (2018-2019 XIX Open Cup, Grand Prix of Korea (Division 2))
  18. 2018.10.17 学习如何使用Shiro
  19. iBatis.net 第一篇 搭建
  20. Windows下 virtualenv 使用

热门文章

  1. T-SQL经典语句(SQL server)
  2. C#和Java交互相关研究
  3. 如何在CentOS 7中添加新磁盘而不用重启系统
  4. (转)AS3-元数据Embed嵌入说明
  5. [置顶] 深入浅出Spring(四) Spring实例分析
  6. 从业者生存质量报告之,教育行业里的IT男
  7. 算法笔记_044:表达式计算求值(Java)
  8. ant design pro (十五)advanced 使用 API 文档工具
  9. excel 永久保存宏命令
  10. 记一次CurrentDirectory导致的问题