Algorithm


D. Animals
time limit per test
2 seconds
memory limit per test
64 megabytes
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.

Examples
input
Copy
3 4
1 1 1
output
Copy
2
input
Copy
3 6
1 1 1
output
Copy
3
Note

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.



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <memory.h>

using namespace std;

const int N = 1e4 + 1;
int n, m, animals[101], dp[N][101];

int calc(int food, int animal) {
    if(animal == n) return 0;
    
    int &res = dp[food][animal];
    
    if(res != -1) return res;
    
    res = 0;
    if(food >= (n - animal) * animals[animal])
        res = max(res, calc(food - ((n - animal) * animals[animal]), animal + 1) + 1);

    return dp[food][animal] = max(res, calc(food, animal + 1));
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    
    cin >> n >> m;
    for(int i = 0; i < n; i++) cin >> animals[i];
    
    memset(dp, -1, sizeof dp);
    cout << calc(m, 0) << endl;
    
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3 4
1 1 1

Output

x
+
cmd
2
Advertisements

Demonstration


Codeforcess Solution 35D. Animals C,C++, Java, Js and Python ,35D. Animals,Codeforcess Solution

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+