Created
January 16, 2012 07:52
-
-
Save kuoe0/1619671 to your computer and use it in GitHub Desktop.
[GCJ] 2011 Qualification - C - Candy Splitting - http://kuoe0.ch/561/gcj-2011-qualification-c-candy-splitting/
This file contains hidden or 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
#include <iostream> | |
#include <cstdio> | |
#include <cstdlib> | |
#include <cstring> | |
using namespace std; | |
#define MAXN 1010 | |
int num[ MAXN ]; | |
int main() { | |
freopen( "C.out", "w", stdout ); | |
int test; | |
scanf( "%d", &test ); | |
for ( int t = 0; t < test; ++t ) { | |
int n; | |
scanf( "%d", &n ); | |
int sum = 0; | |
for ( int i = 1; i <= n; ++i ) | |
scanf( "%d", &num[ i ] ), sum ^= num[ i ]; | |
if ( sum ) { | |
printf( "Case #%d: NO\n", t + 1 ); | |
continue; | |
} | |
sort( num + 1, num + 1 + n ); | |
int now = 0, MAX = -1, current = 0; | |
for ( int i = n; i > 1; --i ) { | |
now ^= num[ i ], sum ^= num[ i ]; | |
current += num[ i ]; | |
if ( now == sum ) | |
MAX = max( MAX, current ); | |
} | |
printf( "Case #%d: %d\n", t + 1, MAX ); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment