Contest link: #852 div2

A

Because the residue of the bundle must <= m, we only need to compare a and b.

void solve()
{
    ll a, b, n, m;
    cin >> a >> b >> n >> m;
 
    auto t = n / (m + 1);
    auto residue = n % (m + 1);

    ll res = t * a * m;
    if (residue != 0) {
        res += min(residue * b, residue * a);
    }

    cout << min({res, n * a, n * b}) << endl;
}

B

Greed is ok

void solve()
{
    int x, y, offset;
    cin >> x >> y;
    offset = y, x -= y, y = 0;

    cout << 2 * x << endl;
    for (int i: vw::iota(0, x))
        cout << i + offset << ' ';
    for (int i: vw::iota(1, x + 1) | vw::reverse)
        cout << i + offset << ' ';
    cout << endl;
}
Last modification:February 12, 2023
如果觉得我的文章对你有用,请随意赞赏