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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
#include <iostream>
#include <limits>
#include <map>
#include <string>
using namespace std;
struct Ingredient {
long capacity;
long durability;
long flavor;
long texture;
long calories;
};
// NOLINTBEGIN
map<string, Ingredient> Ingredients = {
{ "Frosting", { 4, -2, 0, 0, 5 } },
{ "Candy", { 0, 5, -1, 0, 8 } },
{ "Butterscotch", { -1, 0, 5, 0, 6 } },
{ "Sugar", { 0, 0, -2, 2, 1 } }
};
// NOLINTEND
void
part1()
{
long max_score = numeric_limits<long>::min();
for ( int frosting = 0; frosting != 100; ++frosting ) {
for ( int candy = 0; candy != 100 - frosting; ++candy ) {
for ( int butterscotch = 0; butterscotch != 100 - frosting - candy; ++butterscotch ) {
int sugar = 100 - butterscotch - candy - frosting;
if ( sugar < 0 ) {
continue;
}
auto capacity = Ingredients["Frosting"].capacity * frosting + Ingredients["Candy"].capacity * candy + Ingredients["Butterscotch"].capacity * butterscotch + Ingredients["Sugar"].capacity * sugar;
auto durability = Ingredients["Frosting"].durability * frosting + Ingredients["Candy"].durability * candy + Ingredients["Butterscotch"].durability * butterscotch + Ingredients["Sugar"].durability * sugar;
auto flavor = Ingredients["Frosting"].flavor * frosting + Ingredients["Candy"].flavor * candy + Ingredients["Butterscotch"].flavor * butterscotch + Ingredients["Sugar"].flavor * sugar;
auto texture = Ingredients["Frosting"].texture * frosting + Ingredients["Candy"].texture * candy + Ingredients["Butterscotch"].texture * butterscotch + Ingredients["Sugar"].texture * sugar;
// auto calories = Ingredients["Frosting"].calories * frosting + Ingredients["Candy"].calories * candy + Ingredients["Butterscotch"].calories * butterscotch + Ingredients["Sugar"].calories * sugar;
auto score = max(0L, capacity) * max(0L, durability) * max(0L, flavor) * max(0L, texture);
max_score = max(max_score, score);
}
}
}
cout << max_score << endl;
}
void
part2()
{
long max_score = numeric_limits<long>::min();
for ( int frosting = 0; frosting != 100; ++frosting ) {
for ( int candy = 0; candy != 100 - frosting; ++candy ) {
for ( int butterscotch = 0; butterscotch != 100 - frosting - candy; ++butterscotch ) {
int sugar = 100 - butterscotch - candy - frosting;
if ( sugar < 0 ) {
continue;
}
auto capacity = Ingredients["Frosting"].capacity * frosting + Ingredients["Candy"].capacity * candy + Ingredients["Butterscotch"].capacity * butterscotch + Ingredients["Sugar"].capacity * sugar;
auto durability = Ingredients["Frosting"].durability * frosting + Ingredients["Candy"].durability * candy + Ingredients["Butterscotch"].durability * butterscotch + Ingredients["Sugar"].durability * sugar;
auto flavor = Ingredients["Frosting"].flavor * frosting + Ingredients["Candy"].flavor * candy + Ingredients["Butterscotch"].flavor * butterscotch + Ingredients["Sugar"].flavor * sugar;
auto texture = Ingredients["Frosting"].texture * frosting + Ingredients["Candy"].texture * candy + Ingredients["Butterscotch"].texture * butterscotch + Ingredients["Sugar"].texture * sugar;
auto calories = Ingredients["Frosting"].calories * frosting + Ingredients["Candy"].calories * candy + Ingredients["Butterscotch"].calories * butterscotch + Ingredients["Sugar"].calories * sugar;
auto score = max(0L, capacity) * max(0L, durability) * max(0L, flavor) * max(0L, texture);
if ( calories == 500 ) {
max_score = max(max_score, score);
}
}
}
}
cout << max_score << endl;
}
int
main()
{
part1();
part2();
}
|