結果

問題 No.1046 Fruits Rush
ユーザー joybeeeejoybeeee
提出日時 2020-05-12 15:47:20
言語 Java21
(openjdk 21)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 638 bytes
コンパイル時間 3,349 ms
コンパイル使用メモリ 72,396 KB
実行使用メモリ 57,864 KB
最終ジャッジ日時 2023-10-11 14:54:40
合計ジャッジ時間 5,348 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,940 KB
testcase_01 AC 125 ms
56,016 KB
testcase_02 AC 126 ms
56,128 KB
testcase_03 AC 133 ms
55,892 KB
testcase_04 AC 132 ms
55,788 KB
testcase_05 AC 131 ms
55,752 KB
testcase_06 AC 125 ms
56,004 KB
testcase_07 AC 132 ms
55,876 KB
testcase_08 AC 127 ms
55,620 KB
testcase_09 AC 134 ms
56,188 KB
testcase_10 AC 125 ms
56,680 KB
testcase_11 AC 126 ms
55,928 KB
testcase_12 AC 137 ms
55,680 KB
testcase_13 AC 135 ms
55,936 KB
testcase_14 AC 126 ms
55,816 KB
testcase_15 AC 128 ms
57,864 KB
testcase_16 AC 127 ms
55,476 KB
権限があれば一括ダウンロードができます

ソースコード

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 max = Integer.MIN_VALUE;
        PriorityQueue<Integer> pq = new PriorityQueue<>();
        for(int i = 0; i < n; i++) {
        	int num = sc.nextInt();
        	max = Math.max(max, num);
        	if(num > 0)
        		pq.offer(num);
        	if(pq.size() > k) pq.poll();
        }
        int sum = 0;
        while(!pq.isEmpty())
        	sum += pq.poll();
        System.out.println(sum == 0 ? max : sum);
    }
}
0