結果

問題 No.3502 GCD Knapsack
コンテスト
ユーザー kq5y
提出日時 2026-04-17 22:38:23
言語 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
結果
TLE  
実行時間 -
コード長 1,461 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,502 ms
コンパイル使用メモリ 333,252 KB
実行使用メモリ 19,712 KB
最終ジャッジ日時 2026-04-17 22:39:17
合計ジャッジ時間 9,503 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other TLE * 1 -- * 34
権限があれば一括ダウンロードができます

ソースコード

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;

  if (w <= mx) {
    rep(d, w, mx + 1) {
      ll total = 0;
      rep(i, n) {
        if (x[i] % d == 0) total += y[i];
      }
      ans = max(ans, total);
    }
  }

  cout << ans << endl;
  return 0;
}
0