結果

問題 No.2566 美しい整数列
ユーザー Pres1dentPres1dent
提出日時 2023-12-02 16:16:58
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 345 ms / 2,000 ms
コード長 770 bytes
コンパイル時間 1,301 ms
コンパイル使用メモリ 109,052 KB
実行使用メモリ 20,480 KB
最終ジャッジ日時 2024-09-26 20:04:58
合計ジャッジ時間 8,073 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <queue>
using namespace std;
#define int long long
signed main() {
  int n, m; cin >> n >> m;
  vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i];
  vector<int> b(m); for (int i = 0; i < m; i++) cin >> b[i];
  vector<int> c(n); for (int i = 0; i < n; i++) cin >> c[i];
  map<int, int> mp;
  int s = b[0];
  mp[a[0]] -= c[0];
  for (int i = 1; i < n; i++) {
    // s + base == a[i]
    // base = a[i] - s;
    int base = a[i] - s;
    mp[base] -= c[i];
    s += b[i % m];
  }
  int ans = 1ll<<60;
  for (auto [k, v] : mp) {
    ans = min(ans, v);
  }
  for (int i = 0; i < n; i++) {
    ans += c[i];
  }
  cout << ans << endl;

}
0