結果
| 問題 | No.1046 Fruits Rush |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-08 21:32:55 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 505 bytes |
| 記録 | |
| コンパイル時間 | 888 ms |
| コンパイル使用メモリ | 98,848 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-06-10 00:42:48 |
| 合計ジャッジ時間 | 1,742 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 |
ソースコード
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
void solve() {
int n, k;
std::cin >> n >> k;
std::vector<int> xs(n);
for (auto& x : xs) std::cin >> x;
std::sort(xs.rbegin(), xs.rend());
int sum = 0;
for (int i = 0; i < k; ++i) {
if (i > 0 && xs[i] < 0) break;
sum += xs[i];
}
std::cout << sum << std::endl;
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
solve();
return 0;
}