結果

問題 No.1046 Fruits Rush
ユーザー ika__siika__si
提出日時 2020-05-09 07:59:45
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 469 bytes
コンパイル時間 4,521 ms
コンパイル使用メモリ 71,556 KB
実行使用メモリ 56,296 KB
最終ジャッジ日時 2023-09-18 11:40:53
合計ジャッジ時間 5,989 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
55,768 KB
testcase_01 AC 129 ms
55,528 KB
testcase_02 AC 130 ms
55,900 KB
testcase_03 AC 135 ms
55,824 KB
testcase_04 AC 136 ms
55,780 KB
testcase_05 AC 137 ms
55,796 KB
testcase_06 AC 128 ms
55,856 KB
testcase_07 AC 136 ms
56,076 KB
testcase_08 AC 132 ms
55,984 KB
testcase_09 AC 135 ms
56,204 KB
testcase_10 AC 127 ms
56,112 KB
testcase_11 AC 129 ms
55,788 KB
testcase_12 AC 142 ms
55,884 KB
testcase_13 AC 140 ms
55,732 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.math.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();

    long[] a = new long[n];

    for (int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
    }

    Arrays.sort(a);

    long sum = 0;

    for (int i = 0; i < k; i++) {
      if (a[n-i-1] < 0) break;
      sum += a[n-i-1];
    }

    System.out.println(sum);

  }

}
0