-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathe.cpp
More file actions
41 lines (37 loc) · 799 Bytes
/
Copy pathe.cpp
File metadata and controls
41 lines (37 loc) · 799 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
//381A - Sereja and Dima
#include <bits/stdc++.h>
using namespace std;
int main(){
int n, ser = 0, dima = 0, move = 1;
cin >> n;
vector<int> num(n);
for(int i = 0; i<n; i++){
cin >> num[i];
}
while(n--){
if(move == 1){
if(num[0] < num[n]){
ser += num[n];
num.pop_back();
}
else{
ser += num[0];
num.erase(num.begin());
}
move = 2;
}
else if(move == 2){
if(num[0] < num[n]){
dima += num[n];
num.pop_back();
}
else{
dima += num[0];
num.erase(num.begin());
}
move = 1;
}
}
cout << ser << " " << dima;
return 0;
}