結果
| 問題 | No.1046 Fruits Rush |
| コンテスト | |
| ユーザー |
ks2m
|
| 提出日時 | 2020-05-08 21:22:32 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 469 bytes |
| 記録 | |
| コンパイル時間 | 2,169 ms |
| コンパイル使用メモリ | 74,584 KB |
| 実行使用メモリ | 54,268 KB |
| 最終ジャッジ日時 | 2024-07-03 23:20:53 |
| 合計ジャッジ時間 | 5,521 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 WA * 3 |
ソースコード
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 = 0;
for (int i = n - 1; i >= n - k; i--) {
if (a[i] >= 0) {
ans += a[i];
}
}
System.out.println(ans);
}
}
ks2m