結果

問題 No.3502 GCD Knapsack
コンテスト
ユーザー kq5y
提出日時 2026-04-17 22:58:01
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 1,500 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,252 ms
コンパイル使用メモリ 333,088 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2026-04-17 22:58:06
合計ジャッジ時間 4,907 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &in : v)
    is >> in;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++)
    os << v[i] << (i + 1 != (int)v.size() ? " " : "");
  return os;
}

#define OVERLOAD_REP(_1, _2, _3, name, ...) name
#define REP1(i, n) for (auto i = std::decay_t<decltype(n)>{}; (i) != (n); ++(i))
#define REP2(i, l, r) for (auto i = (l); (i) != (r); ++(i))
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP2, REP1)(__VA_ARGS__)

#define sum(l) accumulate(l.begin(), l.end(), 0)
#define all(...) std::begin(__VA_ARGS__), std::end(__VA_ARGS__)
#define rall(...) std::rbegin(__VA_ARGS__), std::rend(__VA_ARGS__)

using ull = unsigned long long;
using ll = long long;
using vi = vector<int>;
using vl = vector<long>;
using vll = vector<long long>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvll = vector<vll>;
using vs = vector<string>;
using pii = pair<int, int>;
using vpii = vector<pii>;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);

  int n, w;
  cin >> n >> w;

  vll x(n), y(n);
  cin >> x >> y;

  int mx = *max_element(all(x));
  ll ans = 0;
  vll s(mx + 1, 0);
  rep(i, n) {
  	s[x[i]] += y[i];
  }

  for (int d = w; d <= mx; d++) {
    ll total = 0;
    for (int m = d; m <= mx; m += d) {
      total += s[m];
    }
    ans = max(ans, total);
  }

  cout << ans << "\n";
  return 0;
}
0