結果

問題 No.3502 GCD Knapsack
コンテスト
ユーザー Enderaoe Lyther
提出日時 2026-04-17 21:22:15
言語 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  
実行時間 22 ms / 2,000 ms
コード長 751 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,775 ms
コンパイル使用メモリ 163,224 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-17 21:22:30
合計ジャッジ時間 6,067 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>

using namespace std;

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

    int N, W;
    cin >> N >> W;

    vector<int> X(N);
    int max_x = 0;
    for (int i = 0; i < N; ++i) {
        cin >> X[i];
        if (X[i] > max_x) max_x = X[i];
    }

    vector<long long> sum_exact(max_x + 1, 0);
    for (int i = 0; i < N; ++i) {
        long long y;
        cin >> y;
        sum_exact[X[i]] += y;
    }

    long long ans = 0;
    for (int d = W; d <= max_x; ++d) {
        long long cur = 0;
        for (int multiple = d; multiple <= max_x; multiple += d) {
            cur += sum_exact[multiple];
        }
        if (cur > ans) ans = cur;
    }

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