結果

問題 No.1046 Fruits Rush
ユーザー joybeeeejoybeeee
提出日時 2020-05-12 15:44:25
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 549 bytes
コンパイル時間 2,694 ms
コンパイル使用メモリ 72,192 KB
実行使用メモリ 56,336 KB
最終ジャッジ日時 2023-10-11 14:49:48
合計ジャッジ時間 5,528 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,852 KB
testcase_01 AC 123 ms
55,564 KB
testcase_02 AC 126 ms
53,624 KB
testcase_03 AC 127 ms
56,308 KB
testcase_04 AC 132 ms
56,216 KB
testcase_05 AC 130 ms
55,848 KB
testcase_06 AC 124 ms
55,888 KB
testcase_07 AC 131 ms
56,200 KB
testcase_08 AC 126 ms
55,588 KB
testcase_09 AC 129 ms
56,116 KB
testcase_10 AC 121 ms
56,336 KB
testcase_11 AC 122 ms
55,564 KB
testcase_12 AC 131 ms
55,716 KB
testcase_13 AC 132 ms
56,136 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();
        PriorityQueue<Integer> pq = new PriorityQueue<>();
        for(int i = 0; i < n; i++) {
        	int num = sc.nextInt();
        	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