-
Notifications
You must be signed in to change notification settings - Fork 0
/
A.cpp
52 lines (51 loc) · 940 Bytes
/
A.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
44
45
46
47
48
49
50
51
52
//Sereja and Dima
#include<stdio.h>
int main()
{
int n,arr[1005],a=0,b=0,i,c,low,high;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
low=0;
high=n-1;
c=1;
while(c<=(n+1))
{
if(c==n+1)
break;
else if(c%2==1)
{
if(arr[low]>arr[high])
{
a=a+arr[low];
low=low+1;
c=c+1;
}
else
{
a=a+arr[high];
high=high-1;
c=c+1;
}
}
else
{
if(arr[low]>arr[high])
{
b=b+arr[low];
low=low+1;
c=c+1;
}
else
{
b=b+arr[high];
high=high-1;
c=c+1;
}
}
}
printf("%d %d\n",a,b);
return 0;
}