結果

問題 No.2549 Paint Eggs
ユーザー inkyamaninkyaman
提出日時 2024-03-24 15:06:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 607 ms / 2,000 ms
コード長 1,293 bytes
コンパイル時間 1,732 ms
コンパイル使用メモリ 125,088 KB
実行使用メモリ 20,696 KB
最終ジャッジ日時 2024-03-24 15:07:10
合計ジャッジ時間 20,401 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 3 ms
6,676 KB
testcase_03 AC 3 ms
6,676 KB
testcase_04 AC 3 ms
6,676 KB
testcase_05 AC 3 ms
6,676 KB
testcase_06 AC 3 ms
6,676 KB
testcase_07 AC 3 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 3 ms
6,676 KB
testcase_10 AC 320 ms
16,544 KB
testcase_11 AC 352 ms
20,000 KB
testcase_12 AC 261 ms
12,632 KB
testcase_13 AC 322 ms
16,100 KB
testcase_14 AC 197 ms
15,936 KB
testcase_15 AC 18 ms
6,676 KB
testcase_16 AC 278 ms
15,076 KB
testcase_17 AC 213 ms
10,872 KB
testcase_18 AC 150 ms
10,032 KB
testcase_19 AC 239 ms
13,160 KB
testcase_20 AC 473 ms
20,696 KB
testcase_21 AC 495 ms
20,696 KB
testcase_22 AC 498 ms
20,696 KB
testcase_23 AC 563 ms
20,696 KB
testcase_24 AC 598 ms
20,696 KB
testcase_25 AC 438 ms
20,696 KB
testcase_26 AC 392 ms
20,696 KB
testcase_27 AC 422 ms
20,696 KB
testcase_28 AC 573 ms
20,696 KB
testcase_29 AC 461 ms
20,696 KB
testcase_30 AC 551 ms
20,696 KB
testcase_31 AC 443 ms
20,696 KB
testcase_32 AC 481 ms
20,696 KB
testcase_33 AC 469 ms
20,696 KB
testcase_34 AC 436 ms
20,696 KB
testcase_35 AC 565 ms
20,696 KB
testcase_36 AC 501 ms
20,696 KB
testcase_37 AC 491 ms
20,696 KB
testcase_38 AC 425 ms
20,696 KB
testcase_39 AC 456 ms
20,696 KB
testcase_40 AC 571 ms
20,696 KB
testcase_41 AC 563 ms
20,696 KB
testcase_42 AC 607 ms
20,696 KB
testcase_43 AC 567 ms
20,696 KB
testcase_44 AC 602 ms
20,696 KB
権限があれば一括ダウンロードができます

ソースコード

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