Skip to content

Instantly share code, notes, and snippets.

@papinianus
Last active October 4, 2016 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save papinianus/19de4f1a3f1913fb48a4cec18cae41d9 to your computer and use it in GitHub Desktop.
Save papinianus/19de4f1a3f1913fb48a4cec18cae41d9 to your computer and use it in GitHub Desktop.
<?php
$L = trim(fgets(STDIN));
$N = trim(fgets(STDIN));
$boxes = explode(' ',trim(fgets(STDIN)));
sort($boxes);
$len = 0;
for($i = 0; $i < $N;) {
if($L >= ($len + $boxes[$i])) {
$len += $boxes[$i];
$i++;
} else {
break;
}
}
echo $i.PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment