-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathIngestion.cpp
More file actions
51 lines (37 loc) · 905 Bytes
/
Ingestion.cpp
File metadata and controls
51 lines (37 loc) · 905 Bytes
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
50
51
#include <iostream>
using namespace std;
const int MAX_N = 101;
const int MAX_M = 20000;
int state[MAX_N][MAX_M];
int courses[MAX_N];
int originalM;
int originalN;
int solve(int capacity, int courseIndex, int prevCapacity)
{
if(courseIndex >= originalN)
{
return 0;
}
if(state[courseIndex][capacity] == 0)
{
int caloriesIfEat = min(courses[courseIndex], capacity);
state[courseIndex][capacity] =
max((solve(capacity * 2 / 3, courseIndex + 1, capacity) + caloriesIfEat), // Eat
max(solve(prevCapacity, courseIndex + 1, capacity), // Don't eat once
solve(originalM, courseIndex + 2, capacity))); // Don't eat twice
}
return state[courseIndex][capacity];
}
int main()
{
int n, m;
cin >> n >> m;
originalM = m;
originalN = n;
for(int i = 0; i < n; i++)
{
cin >> courses[i];
}
cout << solve(m, 0, m) << endl;
return 0;
}