-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path381A.cpp
43 lines (37 loc) · 834 Bytes
/
381A.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
#include <bits/stdc++.h>
using namespace std;
int main(){
int n ;
cin >> n ;
deque<int> arr ;
for(int i = 0 ; i<n ; i++){
int a ;
cin >> a ;
arr.push_back(a);
}
int s = 0 , d = 0 ;
while(arr.size()>0){
if(arr.size()>0){
if(arr[0]>arr[arr.size()-1]){
s = s + arr[0];
arr.pop_front() ;
}
else{
s = s+arr[arr.size()-1];
arr.pop_back();
}
}
if(arr.size()>0){
if(arr[0]>arr[arr.size()-1]){
d = d+arr[0];
arr.pop_front();
}
else{
d = d + arr[arr.size()-1];
arr.pop_back();
}
}
}
cout<<s<<" "<<d;
return 0;
}