結果
問題 | No.5 数字のブロック |
ユーザー | yuki |
提出日時 | 2020-08-20 00:14:12 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 293 ms / 5,000 ms |
コード長 | 684 bytes |
コンパイル時間 | 2,412 ms |
コンパイル使用メモリ | 76,920 KB |
実行使用メモリ | 59,236 KB |
最終ジャッジ日時 | 2024-10-12 10:24:05 |
合計ジャッジ時間 | 9,989 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner in = new Scanner(System.in); long box = in.nextLong(); long N = in.nextLong(); List<Long> list = new ArrayList<>(); for(long i=0; i<N; i++){ long block = in.nextLong(); list.add(block); } // 5 7 10 Collections.sort(list); long sum = 0; long count = 0; for(int i=0; i<N; i++){ if( (sum + list.get(i)) <= box){ sum += list.get(i); count++; } } System.out.println(count); } }