Codeforces
CF Step
Youtube Linkedin Discord Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Code : Kill Monsters (Easy Version)



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

void solve(vector<long long> &a, long long x, long long k) {
    int n = a.size();

    map<int, int> freq;
    for (int i = 0; i < n; i++) {
        freq[a[i]]++;
        freq[a[i]] = min(freq[a[i]], 2);
    }

    n = freq.size();
    vector<int> alive(n);

    a.clear();
    int idx = 0;
    for (auto &[key, val] : freq) {
        a.push_back(key);
        alive[idx++] = val;
    }

    int ans = 0;
    // Apply the operation right now.
    int unsafe = lower_bound(a.begin(), a.end(), x * k) - a.begin();
    ans = unsafe;

    unsafe = lower_bound(a.begin(), a.end(), x) - a.begin();
    for (int i = unsafe; i < n; i++) {
        alive[i] = min(alive[i], 1);
    }

    int taken = 0;
    for (int now = unsafe - 1; now >= 0; now--) {
        taken++;
        alive[now]--;

        // Now, do the operation.
        unsafe = lower_bound(a.begin(), a.end(), a[now] * k) - a.begin();

        int remain = 0;
        for (int i = now; i < unsafe; i++) {
            remain += alive[i];
        }
        ans = max(ans, taken + now + remain);
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;
    while (t--) {
        int n;
        long long x, k;
        cin >> n >> x >> k;
        vector<long long> a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        solve(a, x, k);
    }
    return 0;
}