题解 CF1244C 【The Football Season】
AutumnKite · · 题解
其实就是要求
一开始写了一个扩欧,发现 long long。
回过头来看数据范围,
直接枚举即可。
时间复杂度
#include <cstdio>
long long n, p, a, b, x, y;
int main(){
scanf("%lld%lld%lld%lld", &n, &p, &a, &b);
while (y < a && (p - 1ll * b * y) % a) ++y;
if (y == a) return puts("-1"), 0;
x = (p - 1ll * b * y) / a;
if (x < 0 || x + y > n) return puts("-1"), 0;
printf("%lld %lld %lld\n", x, y, n - x - y);
}