結果
| 問題 | No.1046 Fruits Rush | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-05-08 21:32:55 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 2,000 ms | 
| コード長 | 505 bytes | 
| コンパイル時間 | 1,059 ms | 
| コンパイル使用メモリ | 79,392 KB | 
| 最終ジャッジ日時 | 2025-01-10 08:13:10 | 
| ジャッジサーバーID (参考情報) | judge5 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| 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;
}
            
            
            
        