結果

問題 No.1046 Fruits Rush
ユーザー ks2m
提出日時 2020-05-08 21:24:10
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 472 bytes
コンパイル時間 3,203 ms
コンパイル使用メモリ 74,728 KB
実行使用メモリ 54,588 KB
最終ジャッジ日時 2024-07-03 23:33:15
合計ジャッジ時間 5,592 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 2
other AC * 2 WA * 12
権限があれば一括ダウンロードができます

ソースコード

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