結果
| 問題 | No.1046 Fruits Rush | 
| コンテスト | |
| ユーザー |  ks2m | 
| 提出日時 | 2020-05-08 21:26:28 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 129 ms / 2,000 ms | 
| コード長 | 476 bytes | 
| コンパイル時間 | 2,425 ms | 
| コンパイル使用メモリ | 75,064 KB | 
| 実行使用メモリ | 54,336 KB | 
| 最終ジャッジ日時 | 2024-07-03 23:42:31 | 
| 合計ジャッジ時間 | 5,143 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 14 | 
ソースコード
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[n - 1];
		for (int i = n - 2; i >= n - k; i--) {
			if (a[i] >= 0) {
				ans += a[i];
			}
		}
		System.out.println(ans);
	}
}
            
            
            
        