結果

問題 No.3512 moesode
コンテスト
ユーザー D M
提出日時 2026-05-14 11:12:01
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 801 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,270 ms
コンパイル使用メモリ 340,952 KB
実行使用メモリ 8,416 KB
最終ジャッジ日時 2026-05-14 11:12:07
合計ジャッジ時間 4,478 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

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

    ll n, m, k;
    cin >> n >> m >> k;

    vector<ll> out(n, 0), in(n, 0);

    for (int i = 0; i < m; i++) {
        ll a, b;
        cin >> a >> b;
        --a; --b;
        out[a]++;
        in[b]++;
    }

    ll ans = 0;
    ll active = 0;
    vector<ll> cand;

    for (int i = 0; i < n; i++) {
        ll have = min(in[i], k);

        if (out[i] > 0) {
            active++;
            ans += k - have;
        } else {
            cand.push_back(have);
        }
    }

    ll need = max(0LL, (k + 1) - active);

    sort(cand.rbegin(), cand.rend());

    for (int i = 0; i < need; i++) {
        ans += k - cand[i];
    }

    cout << ans << '\n';
}
0