-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path1036.cpp
52 lines (43 loc) · 1.05 KB
/
1036.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
51
52
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int a[100005];
long long total[3], sum[3];
int getMinIndex() {
if (sum[0] <= sum[1] && sum[0] <= sum[2]) return 0;
else if (sum[1] <= sum[0] && sum[1] <= sum[2]) return 1;
else return 2;
}
int main() {
int n; scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
for (int i = 0; i < n; i += 3) {
total[0] += sum[0];
sum[0] += a[i];
}
for (int i = 1; i < n; i += 3) {
total[1] += sum[1];
sum[1] += a[i];
}
for (int i = 2; i < n; i += 3) {
total[2] += sum[2];
sum[2] += a[i];
}
long long totalTime = total[0] + total[1] + total[2];
long long maxTime = max(max(sum[0], sum[1]), sum[2]);
printf("%lld %lld\n", totalTime, maxTime);
for (int i = 0; i < 3; ++i) {
total[i] = 0; sum[i] = 0;
}
for (int i = 0; i < n; ++i) {
int k = getMinIndex();
total[k] += sum[k];
sum[k] += a[i];
}
totalTime = total[0] + total[1] + total[2];
maxTime = max(max(sum[0], sum[1]), sum[2]);
printf("%lld %lld\n", totalTime, maxTime);
return 0;
}