-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathProgram.cs
34 lines (26 loc) · 863 Bytes
/
Program.cs
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
using System;
namespace Fair_Rations {
class Program {
public static int FairRations(int[] ar) {
int minLoaves = 0;
for (int i = 0; i < ar.Length - 1; i++) {
if (ar[i] % 2 == 1) {
ar[i]++;
ar[i + 1]++;
minLoaves += 2;
}
}
if (ar[ar.Length - 1] % 2 == 1) {
return -1;
} else {
return minLoaves;
}
}
static void Main(string[] args) {
int length = Convert.ToInt32(Console.ReadLine().Trim());
int[] ar = Array.ConvertAll(Console.ReadLine().Split(' '), arTemp => Convert.ToInt32(arTemp));
int result = FairRations(ar);
Console.WriteLine(result == -1 ? "NO" : result);
}
}
}