結果

問題 No.1046 Fruits Rush
ユーザー shinnshinnshinnshinn
提出日時 2020-06-14 18:00:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 469 bytes
コンパイル時間 2,747 ms
コンパイル使用メモリ 71,860 KB
実行使用メモリ 56,396 KB
最終ジャッジ日時 2023-09-09 22:34:22
合計ジャッジ時間 5,979 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
55,820 KB
testcase_01 AC 115 ms
55,540 KB
testcase_02 AC 117 ms
56,396 KB
testcase_03 AC 120 ms
55,708 KB
testcase_04 AC 122 ms
56,276 KB
testcase_05 AC 120 ms
55,652 KB
testcase_06 AC 117 ms
55,996 KB
testcase_07 AC 123 ms
55,828 KB
testcase_08 AC 119 ms
55,896 KB
testcase_09 AC 124 ms
55,900 KB
testcase_10 AC 116 ms
54,164 KB
testcase_11 AC 117 ms
55,796 KB
testcase_12 AC 125 ms
56,072 KB
testcase_13 AC 124 ms
56,044 KB
testcase_14 AC 116 ms
55,652 KB
testcase_15 AC 117 ms
55,420 KB
testcase_16 AC 116 ms
53,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
	}
}
0