-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path230410-1.cpp
More file actions
50 lines (45 loc) · 935 Bytes
/
230410-1.cpp
File metadata and controls
50 lines (45 loc) · 935 Bytes
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 <string>
#include <vector>
using namespace std;
vector<int> p1;
vector<int> p2;
long long solution(vector<int> sequence) {
long long answer = -50000000000;
for(int i = 0; i < sequence.size(); i++)
{
if(i % 2 == 0)
{
p1.push_back(sequence[i]);
p2.push_back(-sequence[i]);
}
if(i % 2 != 0)
{
p1.push_back(-sequence[i]);
p2.push_back(sequence[i]);
}
}
int n = sequence.size();
long long s1 = 0, s2 = 0;
for(int i = 0; i < n; i++)
{
if(s1 > 0)
{
s1 += p1[i];
}
if(s1 <= 0)
{
s1 = p1[i];
}
if(s2 > 0)
{
s2 += p2[i];
}
if(s2 <= 0)
{
s2 = p2[i];
}
answer = max(answer, s1);
answer = max(answer, s2);
}
return answer;
}