結果

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

ソースコード

diff #

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

template<class T> istream& operator >> (istream& is, vector<T>& vec) {
    for(T& x : vec) is >> x;
    return is;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<ll> a(n), b(m), c(n);
    cin >> a >> b >> c;
    ll s = 0, ans = 1ll << 60;
    map<ll, ll> mp;
    mp[a[0]] += c[0];
    for(int i = 1; i < n; i++){
        s += b[(i - 1) % m];
        mp[a[i] - s] += c[i];
    }
    s = accumulate(c.begin(), c.end(), 0ll);
    for(auto &&[key, v] : mp){
        ans = min(ans, s - v);
    }
    cout << ans << '\n';
}
0