結果

問題 No.2566 美しい整数列
ユーザー GOTKAKO
提出日時 2023-12-02 15:35:54
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 194 ms / 2,000 ms
コード長 711 bytes
コンパイル時間 2,330 ms
コンパイル使用メモリ 204,340 KB
最終ジャッジ日時 2025-02-18 04:45:15
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

    int N,M; cin >> N >> M;
    long long sumc = 0;
    vector<long long> A(N),B(M),C(N);
    for(auto &a : A) cin >> a;
    for(auto &b : B) cin >> b;
    for(auto &c : C) cin >> c,sumc += c;

    map<long long,vector<int>> S;
    long long now = A.at(0);
    S[0].push_back(0);
    for(int i=1; i<N; i++){
        now += B.at((i-1)%M);
        S[now-A.at(i)].push_back(i);
    }

    long long answer = sumc;
    for(auto[diff,D] : S){
        long long nowcost = 0;
        for(auto d : D) nowcost += C.at(d);
        answer = min(sumc-nowcost,answer);
    }
    cout << answer << endl;
}
0