-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBytelandianGoldCoins.cpp
More file actions
54 lines (45 loc) · 934 Bytes
/
BytelandianGoldCoins.cpp
File metadata and controls
54 lines (45 loc) · 934 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
52
53
54
#include <iostream>
#include <string>
#include <stdio.h>
#include<vector>
using namespace std;
long long* maxDollars = NULL;
static void findMaxDollars(long long n) {
if(n < 0)
{
return;
}
maxDollars = new long long[n+1];
maxDollars[0] = 0;
for(long long x = 1; x<=n; x++)
{
long long brokenSum = maxDollars[x/2] + maxDollars[x/3] + maxDollars[x/4];
if(brokenSum<x)
{
maxDollars[x] = x;
}
else
{
maxDollars[x] = brokenSum;
}
}
}
int main() {
vector<long long> inputs;
long long maxInput = -1;
long long n;
while (scanf("%lld",&n)!=EOF)
{
if(maxInput < n)
{
maxInput = n;
}
inputs.push_back(n);
}
findMaxDollars(maxInput);
for(int i =0 ; i<inputs.size(); i++)
{
cout<<maxDollars[inputs[i]]<<endl;
}
return 0;
}