結果

問題 No.1046 Fruits Rush
ユーザー ika__siika__si
提出日時 2020-05-09 08:05:45
言語 Java21
(openjdk 21)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 479 bytes
コンパイル時間 1,863 ms
コンパイル使用メモリ 71,516 KB
実行使用メモリ 56,240 KB
最終ジャッジ日時 2023-09-18 11:48:22
合計ジャッジ時間 5,022 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
56,172 KB
testcase_01 AC 121 ms
55,504 KB
testcase_02 AC 123 ms
56,112 KB
testcase_03 AC 127 ms
55,976 KB
testcase_04 AC 128 ms
55,652 KB
testcase_05 AC 129 ms
56,124 KB
testcase_06 AC 122 ms
55,956 KB
testcase_07 AC 128 ms
55,880 KB
testcase_08 AC 124 ms
55,956 KB
testcase_09 AC 127 ms
55,560 KB
testcase_10 AC 120 ms
55,692 KB
testcase_11 AC 122 ms
55,932 KB
testcase_12 AC 131 ms
55,852 KB
testcase_13 AC 134 ms
56,240 KB
testcase_14 AC 119 ms
55,524 KB
testcase_15 AC 121 ms
54,028 KB
testcase_16 AC 122 ms
56,072 KB
権限があれば一括ダウンロードができます

ソースコード

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 (i != 0 && a[n-i-1] < 0) break;
      sum += a[n-i-1];
    }

    System.out.println(sum);

  }

}
0