結果
問題 | No.1046 Fruits Rush |
ユーザー |
![]() |
提出日時 | 2020-05-08 22:32:18 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 404 bytes |
コンパイル時間 | 2,869 ms |
コンパイル使用メモリ | 196,508 KB |
最終ジャッジ日時 | 2025-01-10 09:01:46 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 |
ソースコード
#include <bits/stdc++.h>using namespace std;int main() {int n, k;vector<int> a;cin >> n >> k;for (int i = 0; i < n; i++) {int x;cin >> x;a.push_back(x);}sort(a.begin(), a.end());int ans = 0;ans += a.back();a.pop_back();for (int i = 0; i < k - 1; i++) {if (a.back() > 0) {ans += a.back();a.pop_back();}}cout << ans << "\n";}