結果
問題 |
No.5 数字のブロック
|
ユーザー |
|
提出日時 | 2020-09-17 21:26:22 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 267 ms / 5,000 ms |
コード長 | 542 bytes |
コンパイル時間 | 1,939 ms |
コンパイル使用メモリ | 75,660 KB |
実行使用メモリ | 58,928 KB |
最終ジャッジ日時 | 2024-06-22 06:52:36 |
合計ジャッジ時間 | 9,056 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int c = sc.nextInt(); int h = sc.nextInt(); List<Integer> a = new ArrayList<>(); for(int i=0;i<h;i++) { int x = sc.nextInt(); a.add(x); } Collections.sort(a); int sum =0; int cnt=0; int g=0; while(sum<c && cnt!=h) { sum+=a.get(g); if(sum<=c) { cnt++; } g++; } System.out.println(cnt); } }