P18156 [NWERC 2026] Explosive Experiment

Description

Adam and Jamie are revisiting two of their most famous explosive experiments. In one experiment, they tested whether explosives can remove hardened cement from a cement truck. In another, they tried to reproduce MacGyver’s heroic action to protect bystanders from a bomb by covering it in wet concrete. Their original experiments were spectacular on their own, but one obvious follow-up was missing: how does wet concrete compare to hardened concrete when exposed to explosives? Since they already used almost all of their explosives in previous experiments, they scurry around their headquarters to see if they have anything left. Soon enough, Adam finds $d$ sticks of dynamite past their expiration date. Jamie comes back with a grin under his moustache and $c$ white slabs under his arms: “When in doubt: C4!” Each slab of C4 is guaranteed to go off with power $p$. The dynamite is more explosive, but since it expired, it is also more unpredictable: each stick has exactly twice the power ($2p$), but has only a $50\%$ probability of going off, for each stick independently. A stick of dynamite will always go off if at least one explosive at the same target goes off. They prepare one target with wet concrete and another with hardened concrete, each target requiring a total explosive power of at least $x$ to be destroyed. Distribute the explosives to maximize the probability that both targets are destroyed. And remember, kids, do not try this at home.

Input Format

The input consists of: - One line with four integers $c$, $d$, $x$, and $p$ ($0 \leq c, d \leq 10^9$, $1 \leq x, p \leq 10^9$), the number of slabs of C4, the number of sticks of dynamite, the required power to destroy each target, and the power of one slab of C4. Because “Jamie wants a big boom”, it is guaranteed that there is at least one way to distribute the explosives such that the probability of success is greater than zero.

Output Format

Output a distribution of the explosives to maximize the probability that both targets are destroyed with four nonnegative integers $c_1$, $d_1$, $c_2$, and $d_2$ ($0 \leq c_1 + c_2 \leq c$, $0 \leq d_1 + d_2 \leq d$): the number of slabs of C4 and sticks of dynamite at the first target, and the same for the second target. If there are multiple optimal solutions, you may output any one of them.