Submeter | Todas submissőes | Melhores | Voltar |
COWFIX - Going to the Movies |
Farmer John is taking some of his cows to the movies! While his truck has a limited capacity of C (100 <= C <= 5000) kilograms, he wants to take the cows that, in aggregate, weigh as much as possible without exceeding the limit C.
Given N (1 <= N <= 16) cows and their respective weights W_i, determine the weight of the heaviest group of cows that FJ can take to the movies.
Input
- Line 1: Two space-separated integers: C and N
- Lines 2..N+1: Line i+1 contains a single integer: W_i
Output
- Line 1: A single integer that is the weight of the heaviest group of cows that can go to the movies
Example
Input: 259 5 81 58 42 33 61 Output: 242
81+58+42+61 = 242; this is the best possible sum
Adicionado por: | Wanderley Guimarăes |
Data: | 2008-06-06 |
Tempo limite: | 0.100s |
Tamanho do fonte: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Linguagem permitida: | ADA95 DOC ASM32 BASH BF C CSHARP CPP C99 CLPS LISP sbcl LISP clisp D FORTRAN HASK ICON ICK JAVA LUA NEM NICE OCAML PAS-GPC PAS-FPC PDF PERL PHP PIKE PS PRLG-swi PYTHON RUBY SCM guile SCM qobi ST TEXT WHITESPACE |
Origem: | USACO Open 2008 - Bronze |