-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path381A.cpp
More file actions
71 lines (66 loc) · 1.15 KB
/
381A.cpp
File metadata and controls
71 lines (66 loc) · 1.15 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
//DEFINITE
using namespace std;
#include <iostream>
#include <string>
#include <math.h>
#include <stdio.h>
#include <bits/stdc++.h>
#define mem(x,val) memset((x),(val),sizeof(x));
#define rite(x) freopen(x,"w",stdout);
#define read(x) freopen(x,"r",stdin);
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define pb push_back
#define clr clear()
#define FASTINPUT ios_base::sync_with_stdio(0);cin.tie(0);
typedef long long int lli;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef map<int,int> mii;
typedef set<int> si;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
int main()
{
FASTINPUT
int n;
cin>>n;
vector<int>arr(n);
for(int i=0;i<n;i++)
cin>>arr[i];
int l=0,h=n-1;
int s=0,d=0;
int i=0;
while(l<=h)
{
if(i%2==0)
{
if(arr[l]>arr[h])
{
s+=arr[l];
l+=1;
}
else
{
s+=arr[h];
h-=1;
}
}
else
{
if(arr[l]>arr[h])
{
d+=arr[l];
l+=1;
}
else
{
d+=arr[h];
h-=1;
}
}
i++;
}
cout<<s<<" "<<d<<endl;
return 0;
}