PID-4769-Animals
2016-04-08 19:12
351 查看
C. Animals
Time Limit: 2000msMemory Limit: 65536KB
64-bit integer IO format: %I64d
Java class name: (Any)
Submit Status PID:
4769
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 then-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-thday given that the food was enough for everybody.
Sample Input
Input3 4 1 1 1
Output
2
Input
3 6 1 1 1
Output
3
//题意为一个人要养几天动物,他有多少饲料,每天动物都会来一只,对应的数为它每天的食量。
//一开始会想着用01背包后来直接想根本不用只需要找出那些吃的最少的就行了,算是贪心吧。
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int main() { int n,m; while(~scanf("%d%d",&n,&m)) { int i,j,a[105],eat,sum=0; for(i=0;i<n;i++) { scanf("%d",&eat); a[i]=eat*(n-i); } sort(a,a+n); for(i=0;i<n;i++) { if(m-a[i]>=0) { sum++; m=m-a[i]; } if(m==0) { break; } if(m<0) { sum--; break; } } printf("%d\n",sum); } }
相关文章推荐
- 记一次未解决的异常:java.lang.NoClassDefFoundError: net/sf/json/JSONObject
- 计算数学表达式
- 111
- 修改Python IDLE代码配色及语法高亮主题
- centos6.5环境通达OA数据库mysql5.0.67升级至mysql5.5.48方案
- 1002:归并排序
- 安卓平台架构及特性
- centos6.5环境通达OA数据库mysql5.0.67升级至mysql5.5.48方案
- [Java8 Collection源码+算法+数据结构]-List(二)
- 阐述线程状态之间的关系
- Eclipse的PHP插件PHPEclipse安装和使用
- 线性表 及Java实现 顺序表、链表、栈、队列
- 浅谈套接字编程—TCP
- Android Bluetooth 框架简读 <3>
- (Vagrant Vs Docker)Should I use Vagrant or Docker for creating an isolated environment?
- 第七周项目 用一般函数,成员函数,友元函数求两点之间的距离
- android imageView释放内存
- 辗转相除法
- /usr/bin/ld: cannot find -lc
- php中 如何生成jsonp数据接口及如何调用?