C. Animals
2016-04-09 16:06
225 查看
C. Animals
Time Limit: 2000msMemory Limit: 65536KB64-bit integer IO format: %I64d Java class name:(Any)SubmitStatusPID: 4769Once 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 boxesof 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 exactlyn days in DravDe’s dream and the animal that came on thei-th day, ate exactlyci tons of food daily starting from dayi. 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 exactlyX 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 then-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 fromthat day to the n-th.Input
The first input line contains integers n andX (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 integersci (1 ≤ ci ≤ 300). Numbers in the second line aredivided by a space.Output
Output the only number — the maximum possible amount of animals on the farm by the end of then-th day given that the food was enough for everybody.Sample Input
Input3 41 1 1Output
2Input
3 61 1 1Output
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<stdio.h>#include<algorithm>using namespace std;int a[101];int main(){freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);int n,m,i,j;while(scanf("%d%d",&n,&m)!=-1){for(i=0;i<n;i++){scanf("%d",&a[i]);}int sum=0;for(i=0,j=n;i<n,j>0;i++,j--){a[i]=a[i]*j;//先把每个动物吃到最后一天的食物求出来}sort(a,a+n);//把他们的食物排序if(a[0]>m){printf("0\n");}else{for(i=0;i<n;i++)//从最小的开始找,小于m的就加一: 贪心{if(a[i]<=m){sum++;m-=a[i];}else{break;}}}printf("%d\n",sum);}}
相关文章推荐
- 各种常用正则表达式
- Swift 自己主动引用计数机制ARC
- 结对编程—电梯调度
- 剑指offer-面试题33:把数组排成最小的数
- Eclipse+Maven创建webapp项目
- Educational Codeforces Round 11A. Co-prime Array 数学
- Android 蓝牙开发介绍
- 房屋建筑和市政基础设施工程竣工验收备案管理办法
- powerDesigner设置name不自动等于code
- unity再战PBR材质流程与材质制作实践
- TabLayout+ViewPager+Fragment完成滑动界面
- java 递归算法
- ZOJ2314 Reactor Cooling(无源汇流量有上下界网络的可行流)
- 推荐:移动端前端UI库—Frozen UI、WeUI、SUI Mobile
- Struts2源码分析(二)Struts2运行流程分析
- tcp详解学习笔记-tcp建立终止
- 银行家算法
- 手把手教你配置苹果APNS推送服务
- HDU2042
- Java中super的几种用法并与this的区别