結果

問題 No.1454 ツブ消ししとるなEasy
ユーザー MisterMister
提出日時 2021-03-31 21:26:36
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 812 bytes
コンパイル時間 1,059 ms
コンパイル使用メモリ 79,276 KB
最終ジャッジ日時 2025-01-20 02:53:32
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "main.cpp"
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>

using namespace std;
using lint = long long;

void solve() {
    int n, m, r, l;
    cin >> n >> m >> r >> l;

    vector<lint> xs;
    lint sum = 0;
    while (n--) {
        lint x;
        cin >> x;

        if (x <= l) {
            continue;
        } else if (x >= r) {
            sum += x;
            --m;
        } else {
            xs.push_back(x);
        }
    }

    if (m < 0) {
        cout << "Handicapped\n";
        return;
    }

    sort(xs.begin(), xs.end());
    while (m > 0 && !xs.empty()) {
        sum += xs.back();
        xs.pop_back();
        --m;
    }

    cout << sum << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}
0