結果

問題 No.1046 Fruits Rush
ユーザー kusagame12kusagame12
提出日時 2023-11-22 18:00:23
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 847 bytes
コンパイル時間 2,065 ms
コンパイル使用メモリ 74,264 KB
実行使用メモリ 58,080 KB
最終ジャッジ日時 2023-11-22 18:00:29
合計ジャッジ時間 5,663 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
56,668 KB
testcase_01 AC 121 ms
57,948 KB
testcase_02 AC 123 ms
57,840 KB
testcase_03 AC 129 ms
57,960 KB
testcase_04 AC 131 ms
58,080 KB
testcase_05 AC 129 ms
58,068 KB
testcase_06 AC 114 ms
56,688 KB
testcase_07 AC 131 ms
57,824 KB
testcase_08 AC 125 ms
57,744 KB
testcase_09 AC 118 ms
56,796 KB
testcase_10 AC 123 ms
57,960 KB
testcase_11 AC 126 ms
57,964 KB
testcase_12 AC 135 ms
57,992 KB
testcase_13 AC 132 ms
57,956 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] juices = new int[n];
        for(int i = 0 ; i < n ; i++){
            juices[i] = sc.nextInt();
        }
        
        int ans = 0;
        for(int i = 0 ; i < k ; i++){
            int max = 0;
            int index = -1;
            for(int j = 0 ; j < n ; j++){
                if(juices[j] > max){
                    max = juices[j];
                    index = j;
                }
            }   
            if(max == 0){
                break;
            }
            ans += max;
            juices[index] = -101;
        }
      
        System.out.println(ans);
        
    }
    
}
0