結果

問題 No.2566 美しい整数列
ユーザー momoyuu
提出日時 2023-12-15 14:37:05
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 670 bytes
コンパイル時間 1,373 ms
コンパイル使用メモリ 112,196 KB
実行使用メモリ 20,480 KB
最終ジャッジ日時 2024-09-27 06:25:12
合計ジャッジ時間 5,155 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
using ll = long long;

#include<map>
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n,m;
    cin>>n>>m;
    vector<ll> a(n),b(m),c(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];
    ll sum = 0;
    for(int i = 0;i<n;i++) sum += c[i];
    ll ans = sum;
    map<ll,ll> memo;
    ll tmp = 0;
    for(int i = 0;i<n;i++){
        if(i>0){
            tmp += b[(i-1) % m];
        }
        memo[a[i]-tmp] += c[i];
    }
    for(auto&itr:memo) ans = min(ans,sum-itr.second);
    cout<<ans<<endl;
}
0