All submissions for this problem are available.
Mr. Robert, like so many of her sisters, has put on a few too many
pounds enjoying the delectable grass from Farmer John's pastures.
FJ has put her on a strict diet of no more than H (5 <= H <= 45,000)
kilograms of hay per day.
Mr. Robert can eat only complete bales of hay; once she starts she can't
stop. She has a complete list of the N (1 <= N <= 500) haybales
available to her for this evening's dinner and, of course, wants
to maximize the total hay she consumes. She can eat each supplied
bale only once, naturally (though duplicate weight valuess might
appear in the input list; each of them can be eaten one time).
Given the list of haybale weights W_i (1 <= W_i <= H), determine the
maximum amount of hay Mr. Robert can consume without exceeding her limit
of H kilograms (remember: once she starts on a haybale, she eats
* Line 1: Two space-separated integers: H and N
* Lines 2..N+1: Line i+1 describes the weight of haybale i with a
single integer: W_i
SAMPLE INPUT :
56 4 15 19 20 21
Four haybales of weight 15, 19, 20, and 21. Mr. Robert can eat as many as she
wishes without exceeding the limit of 56 altogether.
* Line 1: A single integer that is the number of kilograms of hay that
Mr. Robert can consume without going over her limit.
SAMPLE OUTPUT :
Mr. Robert can eat three bales (15, 20, and 21) and run right up to the limit
of 56 kg.
|Time Limit:||0.1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.