-
Notifications
You must be signed in to change notification settings - Fork 0
/
_dayso.cpp
51 lines (38 loc) · 878 Bytes
/
_dayso.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
#include <bits/stdc++.h>
#define fto(i, a, b) for (int i = a; i <= b; ++i)
#define pb push_back
#define oo 1000000007
using namespace std;
int n, d[300004], ans, f, x, y, le, chan;
int main() {
freopen("dayso.inp", "r", stdin);
freopen("dayso.out", "w", stdout);
chan = 0; le = oo;
scanf("%d", &n);
if (n == 1) {
int a, b;
scanf("%d%d", &a, &b);
printf("%d\n", b - a);
exit(0);
}
fto(i, 1, 2*n) {
scanf("%d", &d[i]);
if (i%2 == 0 && d[i] > chan) {
chan = d[i];
x = i;
}
else if (i%2 != 0 && d[i] < le) {
le = d[i];
y = i;
}
}
fto(i, 1, n) {
ans += d[2*i-1] - d[2*i];
}
swap(d[x], d[y]);
fto(i, 1, n) {
f += d[2*i-1] - d[2*i];
}
printf("%d\n", max(ans, f));
return 0;
}