【題解】Codeforces 1296D. Fight with Monsters

【題目敘述】https://codeforces.com/contest/1296/problem/D

#include <iostream>
#include <map>
using namespace std;
 
long long n, a, b, k, ans, c;
map <long long, long long> mp;
 
int main() {
    cin >> n >> a >> b >> k;
    for (int i = 0; i < n; i++){
        cin >> c;
        c %= (a+b);
        if (c != 0 && c <= a) ans++;
        else if (c == 0) mp[(b+a-1)/a]++;
        else mp[(c-1)/a]++;
    }
    for (map<long long, long long>::iterator i = mp.begin(); i != mp.end(); i++){
        if (k < i->first) break;
        c = min(i->second, k/i->first);
        k -= c*i->first;
        ans += c;
    }
    cout << ans << "\n";
}
分享本文 Share with friends