-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path381A.cpp
38 lines (38 loc) · 837 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
#include<bits/stdc++.h>
#define ll long long
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
using namespace std;
int main()
{
fastread();
ll int n;
while(cin>>n)
{
ll int a[n];
for(ll int i=1; i<=n; i++)
{
cin>>a[i];
}
ll int beg=1,endi=n,i=1,s=0,d=0;
while(beg<=endi)
{
if(i%2==1)
{
if(a[beg]>=a[endi])
s+=a[beg++];
else
s+=a[endi--];
}
else
{
if(a[beg]>=a[endi])
d+=a[beg++];
else
d+=a[endi--];
}
i++;
}
cout<<s<<" "<<d;
break;
}
}