結果

問題 No.1046 Fruits Rush
ユーザー gemygemy
提出日時 2023-11-22 11:36:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 452 bytes
コンパイル時間 2,253 ms
コンパイル使用メモリ 207,284 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-11-22 11:36:04
合計ジャッジ時間 3,263 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 WA -
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 3 ms
6,676 KB
testcase_09 WA -
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
    // Input
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    // Calculation
    sort(A.rbegin(), A.rend());
    int ans = A[0];
    for (int i = 1; i < N && K; ++i, --K) {
        if (A[i] <= 0) break;
        else ans += A[i];
    }

    // Output
    cout << ans << endl;
}
0