C. The Football Season

这篇博客讨论了如何在丢失比赛结果详细信息的情况下,根据Berland足球联赛的规则,确定球队在一个赛季中赢得、平局和输掉的比赛次数。给定比赛总数、总积分、赢球和平局的得分,需要找出可能的胜利、平局和失败场次的组合。文章提到了一个解决此问题的算法,并给出了示例输入和输出。
摘要由CSDN通过智能技术生成

链接:https://codeforces.com/contest/1244/problem/C

The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets ww points, and the opposing team gets 00 points. If the game results in a draw, both teams get dd points.

The manager of the Berland capital team wants to summarize the results of the season, but, unfortunately, all information about the results of each match is lost. The manager only knows that the team has played nn games and got pp points for them.

You have to determine three integers xx, yy and zz — the number of wins, draws and loses of the team. If there are multiple answers, print any of them. If there is no suitable triple (x,y,z)(x,y,z), report about it.

Input

The first line contains four integers nn, pp, ww and dd (1≤n≤1012,0≤p≤1017,1≤d<w≤105)(1≤n≤1012,0≤p≤1017,1≤d<w≤105) — the number of games, the number of points the team got, the number of points awarded for winning a match, and the number of points awarded for a draw, respectively. Note that w>dw>d, so the number of points awarded for winning is strictly greater than the number of points awarded for draw.

Output

If there is no answer, print −1−1.

Otherwise print three non-negative integers xx, yy and zz — the number of wins, draws and losses of the team. If there are multiple possible triples (x,y,z)(x,y,z), print any of them. The numbers should meet the following conditions:

  • x⋅w+y⋅d=px⋅w+y⋅d=p,
  • x+y+z=nx+y+z=n.

Examples

input

Copy

30 60 3 1

output

Copy

17 9 4

input

Copy

10 51 5 4

output

Copy

-1

input

Copy

20 0 15 5

output

Copy

0 0 20

Note

One of the possible answers in the first example — 1717 wins, 99 draws and 44 losses. Then the team got 17⋅3+9⋅1=6017⋅3+9⋅1=60 points in 17+9+4=3017+9+4=30 games.

In the second example the maximum possible score is 10⋅5=5010⋅5=50. Since p=51p=51, there is no answer.

In the third example the team got 00 points, so all 2020 games were lost.

正解应该是exgcd但作为一个菜鸡我在赛后还是只能学会以下这个神奇的算法

代码:

#include<bits/stdc++.h>
using namespace std;
long long t,n,p,w,d,s,l,k;
int main()
{
	cin>>n>>p>>w>>d;
	int flag=1;
	for(int i=0;i<=w;i++)
	{
		if((p-i*d)%w==0)
		{
			s=(p-i*d)/w;
			k=n-i-s;
			if(s>=0&&k>=0)
			cout<<s<<" "<<i<<" "<<k;
			else
			continue;
			flag=0;
			break;
		}
	}
	if(flag==1)
	cout<<-1;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值