結果

問題 No.1046 Fruits Rush
コンテスト
ユーザー RyumaRyama
提出日時 2020-05-08 22:14:32
言語 C++17(clang)
(clang++ 22.1.2 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 334 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 598 ms
コンパイル使用メモリ 139,648 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2026-05-24 08:59:46
合計ジャッジ時間 1,377 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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 ans = a[n-1];
    for (int i=n-2; i>=n-k&&a[i]>0; i--)
        ans += a[i];

    cout << ans << endl;
}
0