#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 ); } struct stQ { int index; int sum; }; //標準入力を取得 //区切り文字で区切られている文字列を取り出す //取り出した文字列のポインタをポインタ配列にセットする (数値型) //戻り値に合計を返す //lMaxに最大値を返す int split(char *pszStr, int lStrMax, const char *pszDelim, int *palOutList, stQ *pQ, 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 ); pQ->index = lNum; pQ->sum = *palOutList; lSum += *palOutList; if( *palOutList > lMax ) lMax = *palOutList; lNum++; // pszToken = strtok_s(NULL, pszDelim, &pszNext_token); pszToken = strtok( NULL, pszDelim ); palOutList++; pQ++; } } 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}; stQ *Q = new stQ[100*1000]; memset( Q, 0, sizeof( stQ )*100*1000 ); int max = 0; int sum = split( szRead, READ_BUFSIZE, READ_DELIMITER, W, Q, max ); if( sum % 2 || ( max > (sum / 2) ) ) { printf( "impossible\n" ); return 0; } int add = N; bool possible = false; for( int i = 0; Q[i].sum != 0 && !possible; i++ ) { if( Q[i].sum == (sum / 2) ) { possible = true; break; } for( int j = Q[i].index+1; W[j] !=0; j++ ) { if( ( Q[i].sum + W[j] ) < (sum / 2) ) { Q[add].index = j; Q[add].sum = Q[i].sum + W[j]; //printf( "i=%d add=%d Q[add].sum=%d\n", i, add, Q[add].sum ); add++; } else if( ( Q[i].sum + W[j] ) == (sum / 2) ) { possible = true; break; } } } if( possible ) printf( "possible\n" ); else printf( "impossible\n" ); return 0; }