您的位置:首页 > 其它

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

Input
3 41 1 1
Output
2
Input
3 61 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<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);}}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: