-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserejaAndDima.c
53 lines (35 loc) · 872 Bytes
/
serejaAndDima.c
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
#include<stdio.h>
int main(){
int sereja =0, dima=0, n;
scanf("%d",&n);
int turn = 1; // 0 for sereja and 1 for dima
int sIndex = 0;
int eIndex = n-1;
int arr[n];
for(int i = 0; i < n; i++){
scanf("%d",&arr[i]);
}
for(int j = 0; j < n; j++){
if(turn){
if(arr[sIndex] > arr[eIndex]){
sereja += arr[sIndex];
sIndex++;
}else{
sereja += arr[eIndex];
eIndex--;
}
turn = 0;
}else{
if(arr[sIndex] > arr[eIndex]){
dima += arr[sIndex];
sIndex++;
}else{
dima += arr[eIndex];
eIndex--;
}
turn = 1;
}
}
printf("%d %d",sereja,dima);
return 0;
}