hiho week 184 register

Ended

Participants:252

Verdict:Accepted
Score:100 / 100
Submitted:2018-01-09 07:22:31

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#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] )
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX