-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSereja.java
More file actions
38 lines (32 loc) · 889 Bytes
/
Sereja.java
File metadata and controls
38 lines (32 loc) · 889 Bytes
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
import java.util.*;
public class Sereja {
public static void main(String main[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int arr[] = new int[n];
int serej = 0, dima = 0;
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
int left = 0, right = n - 1;
boolean st = true;
while (left <= right) {
int pic;
if (arr[left] >= arr[right]) {
pic = arr[left];
left++;
} else {
pic = arr[right];
right--;
}
if (st) {
serej += pic;
} else {
dima += pic;
}
st = !st;
}
System.out.println(serej + " " + dima);
sc.close();
}
}