-
Notifications
You must be signed in to change notification settings - Fork 0
/
SerejaandDima.java
45 lines (41 loc) · 1.24 KB
/
SerejaandDima.java
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
package Divisions.Div2.Round223;
//code by senurah
public class SerejaandDima {
public static void main(String[] args) {
java.util.Scanner scanner = new java.util.Scanner(System.in);
int n = scanner.nextInt();
if (n >= 1 && n <= 1000) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = scanner.nextInt();
}
int sereja = 0;
int dima = 0;
int i = 0;
int j = n - 1;
boolean isSereja = true;
while (i <= j) {
if (isSereja) {
if (arr[i] > arr[j]) {
sereja += arr[i];
i++;
} else {
sereja += arr[j];
j--;
}
} else {
if (arr[i] > arr[j]) {
dima += arr[i];
i++;
} else {
dima += arr[j];
j--;
}
}
isSereja = !isSereja;
}
System.out.println(sereja + " " + dima);
}
scanner.close();
}
}