結果

問題 No.5 数字のブロック
ユーザー youthfuldays072youthfuldays072
提出日時 2018-05-20 11:32:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 283 ms / 5,000 ms
コード長 730 bytes
コンパイル時間 3,446 ms
コンパイル使用メモリ 75,244 KB
実行使用メモリ 47,912 KB
最終ジャッジ日時 2024-04-29 09:50:56
合計ジャッジ時間 11,115 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
41,340 KB
testcase_01 AC 136 ms
41,216 KB
testcase_02 AC 135 ms
41,308 KB
testcase_03 AC 251 ms
46,144 KB
testcase_04 AC 229 ms
45,492 KB
testcase_05 AC 258 ms
46,584 KB
testcase_06 AC 242 ms
45,988 KB
testcase_07 AC 233 ms
45,640 KB
testcase_08 AC 245 ms
45,776 KB
testcase_09 AC 205 ms
43,348 KB
testcase_10 AC 255 ms
46,736 KB
testcase_11 AC 229 ms
45,840 KB
testcase_12 AC 249 ms
45,684 KB
testcase_13 AC 259 ms
46,352 KB
testcase_14 AC 150 ms
41,624 KB
testcase_15 AC 164 ms
41,452 KB
testcase_16 AC 261 ms
46,148 KB
testcase_17 AC 269 ms
47,912 KB
testcase_18 AC 273 ms
47,032 KB
testcase_19 AC 283 ms
47,688 KB
testcase_20 AC 131 ms
41,148 KB
testcase_21 AC 130 ms
41,032 KB
testcase_22 AC 132 ms
41,216 KB
testcase_23 AC 131 ms
41,556 KB
testcase_24 AC 168 ms
41,596 KB
testcase_25 AC 186 ms
41,896 KB
testcase_26 AC 137 ms
41,236 KB
testcase_27 AC 131 ms
41,512 KB
testcase_28 AC 136 ms
41,432 KB
testcase_29 AC 231 ms
45,680 KB
testcase_30 AC 207 ms
43,676 KB
testcase_31 AC 118 ms
40,104 KB
testcase_32 AC 120 ms
40,472 KB
testcase_33 AC 131 ms
41,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;


public class Main2 {


    public static void main(String[] args) {

    	Scanner sc=new Scanner(System.in);

    	int L=sc.nextInt();
    	int N=sc.nextInt();

    	int[] w=new int[N];

    	for(int i=0;i<N;i++) {

    		w[i]=sc.nextInt();

    	}

    	Arrays.sort(w);

    	int index=0;
    	int counter=0;
    	
    	boolean reachedlastindex=false;

    	while(true) {

    		if(L-w[index]>=0 && !reachedlastindex) {

    			L-=w[index];
    			counter++;
    			
    			if(index==N-1) {
    				reachedlastindex=true;
    			}else{
    			    index++;
    			}

    		}else {
    			break;
    		}

    	}

    	System.out.println(counter);

    	sc.close();

    }




}
0