結果

問題 No.2549 Paint Eggs
ユーザー inkyaman
提出日時 2024-03-24 15:06:44
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 663 ms / 2,000 ms
コード長 1,293 bytes
コンパイル時間 1,219 ms
コンパイル使用メモリ 120,032 KB
最終ジャッジ日時 2025-02-20 13:38:39
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
#include <tuple>
using namespace std;
using ll = long long;

int N, M, K;
int C[202020];
ll A[202020], S[202020];

int main() {

    cin >> N >> M >> K;
    for(int i = 1; i <= N; ++i) cin >> C[i];
    for(int i = 1; i <= M; ++i) cin >> A[i];
    
    multiset<pair<ll,int>> mst;
    for(int i = 1; i <= M; ++i) mst.insert({K*A[i],i});
    vector<ll> cost(M+1, 0);
    for(int i = 1; i <= M; ++i) cost[i] = K*A[i];

    for(int i = 1; i <= K-1; ++i) {
        mst.erase({cost[C[i]], C[i]});
        cost[C[i]] -= A[C[i]];
        mst.insert({cost[C[i]], C[i]});
    }

    ll ans = 1e18;
    for(int i = K; i <= N; ++i) {
        mst.erase({cost[C[i]], C[i]});
        cost[C[i]] -= A[C[i]];
        mst.insert({cost[C[i]], C[i]});

        auto itr = mst.begin();
        ll mn = (*itr).first;
        ans = min(ans, mn);

        mst.erase({cost[C[i-K+1]], C[i-K+1]});
        cost[C[i-K+1]] += A[C[i-K+1]];
        mst.insert({cost[C[i-K+1]], C[i-K+1]});

    }

    cout << ans << endl;

}
0