Confusion about problem 'Save The Barrels'

Below is my solution for problem CMSocial - a social coding app. I finally got 100/100 after guessing. But I have a question.
It is about how exactly that we can use diffuser of the same kind in one room. There are two strategies:
A. We can use multiple diffusers of the same kind in one room in a day,
B. We can only use 1 diffuser per room per day.
I thought it is always strategy B based on the description, my original solution can only give me 20/100.

The current solution seems quite contradictory to me(since I guessed the solution) :slight_smile:

In method f, m is the max value, which means we are following strategy B.
But in the meantime, we check d * k >= r, which means we are following strategy A.

An example,
P = 1, Q = 0, K = 2
bugs = [2, 4, 4]

Using strategy A, it is (4 + 4 + 2) / 2 = 5 days.
Using strategy B, it is 6 days.

Is my thinking process wrong?

#include <bits/stdc++.h>
using ll = long long;
ll ceil(ll a, ll b) {
    return (a + b - 1) / b;
}
bool f(std::vector<ll> &v, ll n, ll p, ll q, ll k, ll d) {
    ll r = 0;
    ll m = 0;
    for (ll i = 0; i < n; ++i) {
        if (v[i] - d * q <= 0) continue;
        ll t = ceil(v[i] - d * q, p);
        r += t;
        m = std::max(m, t);
    }

    return std::max(m, k == 0 ? d + r : ceil(r, k)) <= d;
}

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

    ll n, k;
    std::cin >> n >> k;
    ll p, q;
    std::cin >> p >> q;
    std::vector<ll> v(n);
    for (ll i = 0; i < n; ++i) std::cin >> v[i];

    if (q > p) {
        std::swap(p, q);
        k = n - k;
    }

    p -= q;

    ll l = 0, r = (ll)1e9;
    while (r - l > 1) {
        ll m = l + (r - l) / 2;
        if (f(v, n, p, q, k, m)) r = m;
        else l = m;
    }
    std::cout << r << "\n";
    return 0;
}