Lang:G++
Edit12345678910111213141516171819202122232425262728293031#include <stdio.h>#include <string.h>bool cost[2010] ;int main(){int i, j ;int max ;int n, x, a ;memset( cost, false, sizeof( cost ) ) ;scanf( "%d %d", &n, &x ) ;max = 0 ;cost[0] = true ;for ( i = 0 ; i < n ; ++i ){scanf( "%d", &a ) ;for ( j = max ; j >= 0 ; --j )if ( cost[j] == true ){cost[j + a] = true ;if ( j + a > max )max = j + a ;}}if ( max < x )printf( "-1\n" ) ;else{for ( i = x ; i <= max ; ++i )if ( cost[i] )