/
1041.cpp
50 lines (44 loc) · 905 Bytes
/
1041.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
50
#include <iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
long long dice[6];
int main() {
long long n;
cin >> n;
long long one = 987654321;
long long two = 987654321;
long long three = 987654321;
int m = 0;
for (int i = 0; i < 6; i++)
{
cin >> dice[i];
one = min(one, dice[i]);
m = max(m, (int)dice[i]);
}
if (n == 1)
{
cout << dice[0] + dice[1] + dice[2] + dice[3] + dice[4] + dice[5] - m;
return 0;
}
for (int i = 0; i < 6; i++)
{
for (int j = i + 1; j < 6; j++)
{
if (i + j != 5)
{
two = min(two, dice[i] + dice[j]);
for (int k = j + 1; k < 6; k++)
{
if (j + k != 5 && k + i != 5)
three = min(three, dice[i] + dice[j] + dice[k]);
}
}
}
}
long long p1 = 5 * (n - 2) * (n - 2) + 4 * (n - 2);
long long p2 = 8 * (n - 2) + 4;
cout << (p1 * one) + (p2 * two) + (4 * three);
}