Skip to content

Commit 6b89211

Browse files
authored
Solution
1 parent bd55960 commit 6b89211

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

Fair Rations/Fair_Rations.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/python3
2+
3+
import math
4+
import os
5+
import random
6+
import re
7+
import sys
8+
9+
# Complete the fairRations function below.
10+
def fairRations(B):
11+
suml = 0;
12+
current = -1
13+
paired = -1
14+
distance = 0
15+
total = 0;
16+
17+
for i in B:
18+
suml += i
19+
if(i % 2 == 1 and current == -1):
20+
current = i
21+
paired = -1
22+
distance = 0
23+
elif(current != -1 and i % 2 == 1):
24+
paired = i
25+
current = -1
26+
loavesNeeded = (2 + ((distance + 1) - 1) * 2)
27+
total += loavesNeeded
28+
else:
29+
distance += 1
30+
31+
if(suml % 2 == 1):
32+
return "NO"
33+
else :
34+
return total
35+
36+
if __name__ == '__main__':
37+
fptr = open(os.environ['OUTPUT_PATH'], 'w')
38+
39+
N = int(input())
40+
41+
B = list(map(int, input().rstrip().split()))
42+
43+
result = fairRations(B)
44+
45+
fptr.write(str(result) + '\n')
46+
47+
fptr.close()

0 commit comments

Comments
 (0)