結果

問題 No.1046 Fruits Rush
ユーザー ika__siika__si
提出日時 2020-05-09 07:55:04
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 490 bytes
コンパイル時間 4,280 ms
コンパイル使用メモリ 71,572 KB
実行使用メモリ 57,952 KB
最終ジャッジ日時 2023-09-18 11:21:51
合計ジャッジ時間 6,368 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,756 KB
testcase_01 AC 124 ms
55,556 KB
testcase_02 AC 124 ms
55,944 KB
testcase_03 AC 133 ms
55,780 KB
testcase_04 AC 135 ms
56,184 KB
testcase_05 AC 134 ms
55,820 KB
testcase_06 AC 129 ms
55,988 KB
testcase_07 AC 133 ms
55,668 KB
testcase_08 AC 129 ms
56,100 KB
testcase_09 AC 130 ms
56,084 KB
testcase_10 AC 128 ms
55,764 KB
testcase_11 AC 127 ms
55,676 KB
testcase_12 AC 135 ms
55,988 KB
testcase_13 AC 134 ms
55,448 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();

    int[] a = new int[n];

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

    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