結果
問題 |
No.1046 Fruits Rush
|
ユーザー |
![]() |
提出日時 | 2020-06-14 18:00:38 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 134 ms / 2,000 ms |
コード長 | 469 bytes |
コンパイル時間 | 2,793 ms |
コンパイル使用メモリ | 75,028 KB |
実行使用メモリ | 41,520 KB |
最終ジャッジ日時 | 2024-06-27 15:05:13 |
合計ジャッジ時間 | 5,362 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 |
ソースコード
import java.util.*; public class Main{ public static void main(String[] args){ Scanner scan = new Scanner(System.in); int n = Integer.parseInt(scan.next()); int k = Integer.parseInt(scan.next()); int[] a = new int[n]; for(int i = 0;i < n; ++i){ a[i] = Integer.parseInt(scan.next()); } 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); } }