File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed
Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class Main {
6+ public static void main (String [] args ) throws Exception {
7+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
8+
9+ long n = Long . parseLong(br. readLine());
10+ StringTokenizer st = new StringTokenizer (br. readLine());
11+
12+ long [] d = new long [6 ];
13+ for (int i = 0 ; i < 6 ; i++ ) {
14+ d[i] = Long . parseLong(st. nextToken());
15+ }
16+
17+ if (n == 1 ) {
18+ long sum = 0 ;
19+ long max = 0 ;
20+ for (long v : d) {
21+ sum += v;
22+ if (v > max) max = v;
23+ }
24+ System . out. println(sum - max);
25+ return ;
26+ }
27+
28+ long min1 = Long . MAX_VALUE ;
29+ for (long v : d) {
30+ if (v < min1) min1 = v;
31+ }
32+
33+ long [] p = new long [3 ];
34+ p[0 ] = Math . min(d[0 ], d[5 ]);
35+ p[1 ] = Math . min(d[1 ], d[4 ]);
36+ p[2 ] = Math . min(d[2 ], d[3 ]);
37+ Arrays . sort(p);
38+
39+ long min2 = p[0 ] + p[1 ];
40+ long min3 = p[0 ] + p[1 ] + p[2 ];
41+
42+ long cnt3 = 4 ;
43+ long cnt2 = 8 * (n - 2 ) + 4 ;
44+ long cnt1 = 5 * (n - 2 ) * (n - 2 ) + 4 * (n - 2 );
45+
46+ long ans = min1 * cnt1 + min2 * cnt2 + min3 * cnt3;
47+ System . out. println(ans);
48+ }
49+ }
50+
51+ ```
You can’t perform that action at this time.
0 commit comments