結果
問題 | No.5 数字のブロック |
ユーザー |
|
提出日時 | 2021-02-17 10:15:00 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 775 bytes |
コンパイル時間 | 4,013 ms |
コンパイル使用メモリ | 75,388 KB |
実行使用メモリ | 43,712 KB |
最終ジャッジ日時 | 2024-09-13 20:34:49 |
合計ジャッジ時間 | 10,887 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 13 WA * 21 |
ソースコード
import java.util.Arrays;import java.util.Scanner;public class No00000005_Main {public static void main(String[] args) {Scanner scan = new Scanner(System.in);int lineCnt = 0;int l = 0;int n = 0;String[] wi = null;while(scan.hasNextLine()) {lineCnt++;if(lineCnt == 1) {l = Integer.parseInt(scan.nextLine());} else if(lineCnt == 2) {n = Integer.parseInt(scan.nextLine());} else if(lineCnt == 3) {wi = scan.nextLine().split(" ");}if(lineCnt == 3) {break;}}Arrays.sort(wi);int cnt = 0;int sum = 0;for(int i = 0; i < n; i++) {int temp = Integer.parseInt(wi[i]);if(sum + temp > l) {break;}sum += temp;cnt++;}System.out.println(cnt);scan.close();}}