-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClosing the Loop.py
35 lines (30 loc) · 1.11 KB
/
Closing the Loop.py
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
number_test = int(input())
for _ in range(number_test) :
number_segment = int(input())
longeurs = input().split(" ")
if number_segment == 1 :
print("Case #",_ + 1,": ",0,sep="")
else :
rouge = []
bleu = []
boucle = []
for longeur in longeurs :
if longeur[-1] == 'B' :
bleu.append(int(longeur[:-1]))
elif longeur[-1] == 'R' :
rouge.append(int(longeur[:-1]))
if len(rouge) == 0 or len(bleu) == 0 :
print("Case #",_ + 1,": ",0,sep="")
else :
while True :
if len(boucle) % 2 != 0 and len(rouge) != 0 :
boucle.append(max(rouge))
rouge.remove(max(rouge))
elif len(boucle) % 2 == 0 and len(bleu) != 0 :
boucle.append(max(bleu))
bleu.remove(max(bleu))
else :
break
if len(boucle) % 2 != 0 :
boucle.remove(boucle[-1])
print("Case #",_ + 1,": ",sum(boucle) - len(boucle),sep="")