CF1244C The Football Season

题目描述

Berland Capital Team 比了 $n$ 场比赛,总得分为 $p$。已知胜一场得 $w$ 分,平一场得 $d$ 分,败一场不得分。 求任意一组 $(x,y,z)$ 使得如果 Berland Capital Team 胜 $x$ 场,平 $y$ 场,败 $z$ 场时总分为 $p$。如果不存在这样的三元组,输出 $-1$。 ### 形式化题意 求下列方程组的任意一组非负整数解,无解输出 $-1$: $$ \begin{cases} x\cdot w+y\cdot d=p\\ x+y+z=n \end{cases} $$

输入格式

一行四个正整数 $n,p,w,d$。保证 $1\leqslant n\leqslant 10^{12},0\leqslant p\leqslant10^{17},1\leqslant d\lt w\leqslant10^5$。

输出格式

如果方程组无解,输出 $-1$。否则输出一行三个非负整数 $x,y,z$ 表示方程组的一组解。

说明/提示

One of the possible answers in the first example — $ 17 $ wins, $ 9 $ draws and $ 4 $ losses. Then the team got $ 17 \cdot 3 + 9 \cdot 1 = 60 $ points in $ 17 + 9 + 4 = 30 $ games. In the second example the maximum possible score is $ 10 \cdot 5 = 50 $ . Since $ p = 51 $ , there is no answer. In the third example the team got $ 0 $ points, so all $ 20 $ games were lost.