結果
| 問題 | No.1046 Fruits Rush |
| コンテスト | |
| ユーザー |
ks2m
|
| 提出日時 | 2020-05-08 21:26:28 |
| 言語 | Java (openjdk 25.0.2) |
| 結果 |
AC
|
| 実行時間 | 66 ms / 2,000 ms |
| コード長 | 476 bytes |
| 記録 | |
| コンパイル時間 | 2,433 ms |
| コンパイル使用メモリ | 82,528 KB |
| 実行使用メモリ | 42,556 KB |
| 最終ジャッジ日時 | 2026-03-25 06:59:04 |
| 合計ジャッジ時間 | 4,347 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 |
ソースコード
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
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();
}
sc.close();
Arrays.sort(a);
int ans = a[n - 1];
for (int i = n - 2; i >= n - k; i--) {
if (a[i] >= 0) {
ans += a[i];
}
}
System.out.println(ans);
}
}
ks2m