-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path034-ioi-05-p3-mean-sequence.cpp
More file actions
75 lines (74 loc) · 1.64 KB
/
Copy path034-ioi-05-p3-mean-sequence.cpp
File metadata and controls
75 lines (74 loc) · 1.64 KB
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
/*
* IOI '05 P3 - Mean Sequence [ioi05p3]
* Problem: https://dmoj.ca/problem/ioi05p3
* Verdict: ACCEPTED (12.0 pts) Solved: 2023-03-13
* Language: C++20
* Runtime: 1.985463826 s Memory: 3452.0 KB
* Source: https://dmoj.ca/src/5407375
*/
/*
ID: BidoTeima
LANG: C++11
TASK:
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void moo(string filename);
void ACPLS(string str = "")
{
if(str=="NOF")return;
if(str.size() && str != "IIOT")
moo(str);
else if(str != "IIOT"){
#ifndef ONLINE_JUDGE
freopen("output.txt", "w", stdout);
freopen("input.txt", "r", stdin);
#endif
}
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
void moo(string fileName){
freopen((fileName+".in").c_str(),"r",stdin);
freopen((fileName+".out").c_str(),"w",stdout);
}
#define tcccc \
int tttttt/*,subtask*/; \
cin >> tttttt/* >> subtask*/; \
while (tttttt--)/*end
*/
int main()
{
ACPLS("");
int n;
cin>>n;
ll sumodd = 0, sumeven = 0, mn = -2e9, mx = 2e9;
for(int i = 0; i < n; i++){
ll m;
cin>>m;
if(i%2==0)sumeven+=m;
else sumodd+=m;
if(!i){
mx = min(mx, m);
continue;
}
ll x = 2 * (sumeven - sumodd);
if(i & 1){
x *= -1;
// x >= m[i]
// x + s >= m[i]
// s >= m[i] - x
mn = max(mn, m - x);
}
else{
// x >= m[i]
// x - s >= m[i]
// x >= m[i] + s
// x - m[i] >= s
mx = min(mx, x - m);
}
}
cout<<max(mx-mn+1,0ll)<<'\n';
}