結果

問題 No.1046 Fruits Rush
ユーザー ika__si
提出日時 2020-05-09 07:57:30
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 493 bytes
コンパイル時間 3,479 ms
コンパイル使用メモリ 74,244 KB
実行使用メモリ 54,468 KB
最終ジャッジ日時 2024-07-05 02:39:55
合計ジャッジ時間 5,732 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 11 WA * 3
権限があれば一括ダウンロードができます

ソースコード

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