結果

問題 No.3502 GCD Knapsack
コンテスト
ユーザー MaTi
提出日時 2026-04-19 19:45:51
言語 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
結果
WA  
実行時間 -
コード長 1,615 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,249 ms
コンパイル使用メモリ 334,148 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2026-04-19 19:45:59
合計ジャッジ時間 6,914 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,a,b) for (int i=a; i<b; i++)
#define rrep(i,a,b) for(int i=a; i>=b; i--)
#define fore(i,a) for(auto &i:a)
#define pb push_back
#define _GLIBCXX_DEBUG
template <typename T> inline bool chmin(T& a, const T& b) {bool c=a>b; if(a>b) a=b; return c;}
template <typename T> inline bool chmax(T& a, const T& b) {bool c=a<b; if(a<b) a=b; return c;}
template <typename T> inline T gcd(T a,T b) {return (b==0)?a:gcd(b,a%b);}
template <typename T> inline T lcm(T a, T b) {return (a*b)/gcd(a,b);}
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;

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

  int n,w;
  cin >> n >> w;
  bool flag = false;
  vll g(200001, 0);
  vll X(n), Y(n);
  rep(i,0,n){
    cin >> X[i];
  }
  rep(i,0,n){
    cin >> Y[i];
  }
  
  
  rep(i,0,n){
    ll x = X[i];
    ll y = Y[i];
    if(x < w) continue;//予選落ち
    if(!flag and x >= w){
      flag = true;
    }
    if(flag){
      rep(j,w,floor(sqrt(x))+1){
        if(x % j == 0){
          g[j] += y;
        }
      }
      g[x] += y;//最後
    }
  }
  
  /*rep(i,0,10){
    cout << g[i] << " ";
  }*/
  
  ll ans = 0;
  if(!flag){
    cout << 0 << endl;
  } else{
      rep(i,w,200001){
        chmax(ans, g[i]);
      }
      cout << ans << endl;
  }
  cout << fixed << setprecision(30);
  return 0;
}
0