結果

問題 No.1046 Fruits Rush
ユーザー kya_ski
提出日時 2020-05-09 10:28:14
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 306 bytes
コンパイル時間 1,543 ms
コンパイル使用メモリ 171,992 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-05 07:01:16
合計ジャッジ時間 2,220 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int &e : a) cin >> e;
	sort(a.begin(), a.end(), greater<int>());
	
	int ans = a[0];
	for (int i = 1; i < k; i++) {
		if (a[i] < 0) break;
		ans += a[i];
	}
	
	cout << ans << '\n';
	
	return 0;
}
0