$value_mid ) { $pl--; } if ( $pf <= $pl ) { list( $data[$pl], $data[$pf] ) = array( $data[$pf], $data[$pl] ); $pf++; $pl--; } } while ($pf <= $pl); if ( $first < $pl ) { quick_sort($data, $first, $pl); } if ( $pf < $last ) { quick_sort( $data, $pf, $last ); } } $box = trim( fgets( STDIN ) ); $num = trim( fgets( STDIN ) ); $data = explode( " ", trim( fgets( STDIN ) ) ); $fill = 0; $idx = 0; // 自前でクイックソート quick_sort( $data, 0, count( $data ) - 1 ); foreach( $data as $w ){ //あふれたら終わり if( ( $fill += $w ) > $box ){ break; } $idx++; } printf( "%d\n", $idx );