Created
April 11, 2012 21:55
-
-
Save irokez/2363015 to your computer and use it in GitHub Desktop.
Problem C. Candy Splitting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
T = int(sys.stdin.readline().strip()) | |
for t in range(T): | |
C = int(sys.stdin.readline().strip()) | |
num = sorted(int(n) for n in sys.stdin.readline().strip().split(' ')) | |
left = 0 | |
right = 0 | |
realsum = 0 | |
for n in num: | |
right ^= n | |
realsum += n | |
cur = num.pop(0) | |
realsum -= cur | |
left = cur | |
right ^= cur | |
while left != right and len(num): | |
cur = num.pop(0) | |
if not len(num): | |
break | |
# print(cur, left, right, realsum) | |
left ^= cur | |
right ^= cur | |
realsum -= cur | |
print('Case #{0}: {1}'.format(t + 1, realsum if left == right else 'NO')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment