結果

問題 No.1046 Fruits Rush
ユーザー tentententen
提出日時 2020-11-09 20:24:09
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 499 bytes
コンパイル時間 1,717 ms
コンパイル使用メモリ 72,116 KB
実行使用メモリ 56,464 KB
最終ジャッジ日時 2023-09-29 22:14:51
合計ジャッジ時間 4,743 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
56,000 KB
testcase_01 AC 111 ms
56,088 KB
testcase_02 AC 109 ms
56,440 KB
testcase_03 AC 111 ms
55,988 KB
testcase_04 AC 119 ms
55,884 KB
testcase_05 AC 118 ms
55,732 KB
testcase_06 AC 112 ms
56,124 KB
testcase_07 AC 115 ms
55,924 KB
testcase_08 AC 114 ms
56,412 KB
testcase_09 AC 113 ms
56,024 KB
testcase_10 AC 113 ms
55,772 KB
testcase_11 AC 111 ms
56,464 KB
testcase_12 AC 122 ms
56,108 KB
testcase_13 AC 121 ms
55,672 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        Arrays.sort(arr);
        long ans = 0;
        for (int i = 0; i < k && arr[n - 1 - i] > 0; i++) {
            ans += arr[n - 1 - i];
        }
        System.out.println(ans);
    }
}
0