-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSolution.java
More file actions
37 lines (33 loc) · 906 Bytes
/
Solution.java
File metadata and controls
37 lines (33 loc) · 906 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
package Practice.Algorithms.Implementation.FairRations;
import java.util.Scanner;
public class Solution {
private static int fairRations(int[] B) {
int sum = 0;
for (int b : B) sum += b;
if (sum % 2 == 1) return -1;
sum = 0;
for (int i = 0; i < B.length; i++) {
if (B[i] % 2 == 1) {
B[i]++;
B[i + 1]++;
sum += 2;
}
}
return sum;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
int[] B = new int[N];
for (int B_i = 0; B_i < N; B_i++) {
B[B_i] = in.nextInt();
}
int result = fairRations(B);
if (result > -1) {
System.out.println(result);
} else {
System.out.println("NO");
}
in.close();
}
}