結果

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

    ll N, M, sm=0, ans=1e18;
    cin >> N >> M;
    vector<ll> A(N), B(M), C(N), S(N);
    for (int i=0; i<N; i++) cin >> A[i];
    for (int i=0; i<M; i++) cin >> B[i];
    for (int i=0; i<N; i++) cin >> C[i];

    for (int i=0; i<N-1; i++){
        S[i+1] = S[i] + B[i % M];
    }

    map<ll, ll> mp;
    for (int i=0; i<N; i++){
        mp[A[i]-S[i]] += C[i];
        sm += C[i];
    }

    for (auto [x, y] : mp){
        ans = min(ans, sm-y);
    }

    cout << ans << endl;

    return 0;
}
0