Skip to content

Instantly share code, notes, and snippets.

@kuoe0
Created January 16, 2012 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuoe0/1619671 to your computer and use it in GitHub Desktop.
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/
#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