-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path15jan_grindingGeek.cpp
49 lines (41 loc) · 1.04 KB
/
15jan_grindingGeek.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//{ Driver Code Starts
#include<bits/stdc++.h>
using namespace std;
// } Driver Code Ends
class Solution{
public:
int max_courses(int n, int total, vector<int> &cost)
{
vector<vector<int>> dp(n + 1, vector<int> (total + 1, 0));
for(int i = n - 1; i > -1; i--){
for(int j = 0; j < total + 1; j++){
int take = 0, notake = 0;
notake = dp[i + 1][j];
if(cost[i] <= j){
int rem = j - cost[i] + (cost[i] * 9) / 10;
take = 1 + dp[i + 1][rem];
}
dp[i][j] = max(take, notake);
}
}
return dp[0][total];
}
};
//{ Driver Code Starts.
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int k;
cin>>k;
vector<int> arr(n);
for(int i=0;i<n;i++) cin>>arr[i];
Solution ob;
cout<<ob.max_courses(n,k,arr)<<endl;
}
}
// } Driver Code Ends