比赛 2025暑假集训第一场 评测结果 WWWWWWWWWWWWWWWWWWWW
题目名称 挑战 NPH 最终得分 0
用户昵称 健康铀 运行时间 0.452 s
代码语言 C++ 内存使用 11.34 MiB
提交时间 2025-06-25 10:23:35
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int g(int a, int b) { return b ? g(b, a % b) : a; }

int main() {
	freopen("NPH.in","r",stdin);
		freopen("NPH.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int T;
    cin >> T;
    while (T--) {
        int n;
        ll k;
        cin >> n >> k;
        vector<int> w(n);
        for (int &x : w) cin >> x;
        int d = w[0];
        for (int x : w) d = g(d, x);
        vector<int> v(n);
        for (int i = 0; i < n; i++) v[i] = w[i] / d;
        ll K = k + 1;
        if (K == 1) {
            cout << "0\n";
            continue;
        }
        vector<ll> dp(1000001, 0);
        dp[0] = 1;
        ll c = 1;
        int s = 1;
        for (; s <= 1000000; s++) {
            dp[s] = 0;
            for (int x : v) if (x <= s) dp[s] += dp[s - x];
            c += dp[s];
            if (c >= K) break;
        }
        cout << (ll)s * d << '\n';
    }
    return 0;
}