結果

問題 No.1046 Fruits Rush
ユーザー ika__siika__si
提出日時 2020-05-09 07:57:30
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 493 bytes
コンパイル時間 5,811 ms
コンパイル使用メモリ 71,480 KB
実行使用メモリ 56,100 KB
最終ジャッジ日時 2023-09-18 11:34:17
合計ジャッジ時間 7,259 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
55,900 KB
testcase_01 AC 129 ms
55,820 KB
testcase_02 AC 130 ms
56,004 KB
testcase_03 AC 135 ms
55,708 KB
testcase_04 AC 138 ms
56,100 KB
testcase_05 AC 139 ms
55,688 KB
testcase_06 AC 135 ms
55,496 KB
testcase_07 AC 139 ms
55,780 KB
testcase_08 AC 133 ms
55,728 KB
testcase_09 AC 135 ms
55,964 KB
testcase_10 AC 129 ms
55,544 KB
testcase_11 AC 130 ms
55,716 KB
testcase_12 AC 139 ms
55,556 KB
testcase_13 AC 140 ms
53,816 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 = n-1; i > n-k-1; i--) {
      if (sum > sum + a[i]) {
        break;
      }
      sum += a[i];
    }

    System.out.println(sum);

  }

}
0