結果

問題 No.1046 Fruits Rush
ユーザー ks2mks2m
提出日時 2020-05-08 21:24:10
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 472 bytes
コンパイル時間 1,907 ms
コンパイル使用メモリ 72,668 KB
実行使用メモリ 58,400 KB
最終ジャッジ日時 2023-09-17 01:20:12
合計ジャッジ時間 5,011 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 120 ms
55,780 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 135 ms
56,192 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 122 ms
56,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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[0];
		for (int i = n - 2; i >= n - k; i--) {
			if (a[i] >= 0) {
				ans += a[i];
			}
		}
		System.out.println(ans);
	}
}
0