結果

問題 No.1046 Fruits Rush
ユーザー ika__siika__si
提出日時 2020-05-09 07:54:07
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 489 bytes
コンパイル時間 3,113 ms
コンパイル使用メモリ 71,244 KB
実行使用メモリ 58,056 KB
最終ジャッジ日時 2023-09-18 11:19:42
合計ジャッジ時間 6,338 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
56,164 KB
testcase_01 AC 125 ms
55,912 KB
testcase_02 AC 125 ms
55,904 KB
testcase_03 AC 133 ms
55,952 KB
testcase_04 AC 136 ms
55,556 KB
testcase_05 AC 134 ms
55,592 KB
testcase_06 AC 129 ms
55,792 KB
testcase_07 AC 136 ms
56,020 KB
testcase_08 AC 130 ms
55,936 KB
testcase_09 AC 133 ms
56,144 KB
testcase_10 AC 128 ms
55,852 KB
testcase_11 AC 132 ms
55,744 KB
testcase_12 AC 135 ms
55,588 KB
testcase_13 AC 136 ms
55,844 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);

    int 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