-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFairRations.java
More file actions
49 lines (35 loc) · 999 Bytes
/
FairRations.java
File metadata and controls
49 lines (35 loc) · 999 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
39
40
41
42
43
44
45
46
47
48
49
// Very simple logic based on the fact that E + E = E and O + O = E
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int n,loaves=0;
n = scanner.nextInt();
int arr[] = new int[n];
for(int i=0;i<n;i++)
arr[i]=scanner.nextInt();
int sum = 0;
for(int i=0;i<arr.length;i++){
sum+=arr[i];
}
int len = arr.length;
if(sum%2==0){
for(int i = 0; i<len; i++){
if(arr[i] % 2 != 0){
arr[i] = arr[i] + 1;
arr[i+1] = arr[i+1] + 1;
loaves+=2;
}
}
System.out.println(loaves);
}
else
System.out.println("NO");
}
}