#include #include #include #define READ_BUFSIZE ( 3*100+100+1 ) #define READ_DELIMITER ( " " ) //標準入力取得(1行) int GetStdin( char* pszStr, int lMaxLen ) { int lLen = 0; memset( pszStr, 0, lMaxLen ); if( fgets( pszStr, lMaxLen, stdin ) ) { lLen = strlen( pszStr ); if( lLen >= 1 ) { if( pszStr[ lLen - 1 ] == 0x0A ) { pszStr[ lLen - 1 ] = 0; lLen--; } } } return( lLen ); } int split(char *pszStr, int lStrMax, const char *pszDelim, int *palOutList, int &lMax) { char *pszToken; int count = 0; char *pszNext_token = 0; int lLen = 0; int lNum = 0; int lSum = 0; lMax = 0; memset( pszStr, 0, lStrMax ); lLen = GetStdin( pszStr, lStrMax ); if( lLen > 0 ) { pszToken = strtok( pszStr, pszDelim ); while ( pszToken != NULL ) { *palOutList = atoi( pszToken ); lSum += *palOutList; if( *palOutList > lMax ) lMax = *palOutList; lNum++; // pszToken = strtok_s(NULL, pszDelim, &pszNext_token); pszToken = strtok( NULL, pszDelim ); palOutList++; } } return lSum; } int main(int argc, char *argv[]) { char szRead[READ_BUFSIZE] = ""; //char* psOutbuf[10000] = { 0 }; int lInput[4] = {0}; GetStdin( szRead, READ_BUFSIZE ); int N = atoi( szRead ); int W[100+1] = {0}; bool possible = false; int max = 0; int sum = split( szRead, READ_BUFSIZE, READ_DELIMITER, W, max ); int T = sum / 2; if( sum % 2 || ( max > T ) ) { printf( "impossible\n" ); return 0; } int* pP = new int[ T + 1]; memset( pP, 0, sizeof( int )*(T+1) ); pP[0] = 1; for( int i = 0; i < N && !possible; i++ ) { for( int j = T; j >=0 && !possible ; j-- ) { if( pP[ j ] != 0 ) { if( W[i] + j <= T && pP[W[i] + j] == 0 ) { pP[ W[i] + j ] = 1; // printf( "%d", W[i] + j ); } if( W[i] + j == T ) possible = true; } } } if( possible ) printf( "possible\n" ); else printf( "impossible\n" ); return 0; }