Codeforces 35D Animals

Source: Internet
Author: User

G-animalsTime limit:2000MS Memory Limit:65536KB 64bit IO Format:%i64d &%i64 U SubmitStatusPracticecodeforces 35D

Description

Inputinput.txtoutputoutput.txt

Once Upon a time dravde, an outstanding person famous in 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, have 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 exactl Y ci tons of food daily starting from day I. But if one day the animal could isn't 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 what many animals were on the farm by the end of the n-T H Day any more, but he does remember that nobody got sad (as it is a happy farm) and that there was the maximum possible a Mount of the animals. That's the number he wants you to find out.

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

Input

The first input line contains integers n and X (1≤ n ≤ 100, 1≤ X ≤10 4)-amount of days in Dravde's dream and the total amount of food (in tons) is there initially. The second line contains integers ci (1≤ ci ≤300). Numbers in the second line is 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 giv En that is 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 would eat one ton of food on the second day and one ton on the third day. The third animal would eat one ton of food on the third day.

#include <iostream>#include<cstdio>#include<fstream>using namespacestd;intani[1005];intdp[100005];intMain () {Freopen ("Input.txt","R", stdin); Freopen ("output.txt","W", stdout); intn,x; CIN>>n>>x; //scanf ("%d%d", &n,&x);     for(intI=1; i<=n; i++) {scanf ("%d",&Ani[i]); Ani[i]*= (n-i+1); }     for(intI=1; i<=n;i++)         for(intj=x;j>=ani[i];j--) Dp[j]=max (dp[j],dp[j-ani[i]]+1); //printf ("%d\n", Dp[x]);cout<<dp[x]<<Endl; return 0;}
View Code

This problem can be DP, can also be greedy. The idea of greed is relatively simple. According to the consumption from small to large order, from the beginning to take it.

The idea of DP is:

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

DP[X] Indicates the maximum number of animals that can be kept when food is x.

Codeforces 35D Animals

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.