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:
Read integers and .
Compute C = 2B (total shadow).
Compute the uncovered part: \text{ans} = \max(0,\, A - C).
Output .
The solution runs in time and uses memory.
#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;
}