結果
| 問題 | No.1046 Fruits Rush | 
| コンテスト | |
| ユーザー |  merom686 | 
| 提出日時 | 2020-05-08 21:22:28 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 514 bytes | 
| コンパイル時間 | 857 ms | 
| コンパイル使用メモリ | 94,352 KB | 
| 最終ジャッジ日時 | 2025-01-10 07:54:02 | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 14 | 
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;
int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int s = 0;
    for (int i = 0; i < k; i++) {
        int t = a[n - 1 - i];
        if (i > 0 && t <= 0) break;
        s += t;
    }
    cout << s << endl;
    return 0;
}
            
            
            
        