Beach#11820

Beach (Çözgüdiň düşündirişi)

Solution Explanation

Kostya has a blanket of length and two umbrellas. Each umbrella creates a shadow of length .

The umbrellas may overlap or extend beyond the blanket, and we want to minimize the part of the blanket that remains uncovered.

The maximum total shadow that both umbrellas can create is:

If 2B \ge A, then the entire blanket can be covered. If 2B < A, then exactly A - 2B units remain uncovered.

Thus the answer is:

\max(0,\, A - 2B)

Algorithm

Complexity

The solution runs in time and uses memory.

Reference Implementation

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

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

    int A, B;
    cin >> A >> B;

    int ans = max(0, A - 2 * B);
    cout << ans << "\n";

    return 0;
}