結果

問題 No.3297 Bake Cookies
ユーザー manabeai
提出日時 2025-10-05 14:36:05
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 1,208 bytes
コンパイル時間 2,006 ms
コンパイル使用メモリ 204,652 KB
実行使用メモリ 15,216 KB
最終ジャッジ日時 2025-10-05 14:36:20
合計ジャッジ時間 5,263 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
// #ifdef DEBUG
// #include "cpp-dump/dump.hpp"
// #define dump(...) cpp_dump(__VA_ARGS__)
// #else
// #define dump(...)
// #endif
using namespace std;
typedef long long ll;

void solve() {
    ll n,m,t;
    cin >> n >> m >> t;

    vector<ll> A(m);
    for (ll i = 0; i < m; ++i) cin >> A[i];
    vector<ll> tmp(n);
    for (ll i = 0; i < m; ++i) {
        tmp[A[i]-1]++;
    }

    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, less<pair<ll, ll>>> big_que;
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> small_que;
    for (ll i = 0; i < n; ++i) {
        small_que.push({tmp[i],i});
        big_que.push({tmp[i],i});
    }
    ll ans = big_que.top().first;
    while (1) {
        pair<ll, ll> big = big_que.top();
        pair<ll, ll> sml = small_que.top();

        if (big.first - 1 > sml.first + t) {
            ans = big.first - 1;
            big.first -= 1;

            sml.first += t;

            big_que.pop();
            small_que.pop();
            big_que.push(big);
            small_que.push(sml);

        } else {
            break;
        }
    }
    
    cout << ans << endl;
}

int main() {
    solve();
    return 0;
}
0