CodeForces-1244C-The Football Season如何巧妙解决比赛胜负问题?

2026-04-17 00:121阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计1139个文字,预计阅读时间需要5分钟。

CodeForces-1244C-The Football Season如何巧妙解决比赛胜负问题?

The football season has just concluded in Berland. Each match is played between two teams, with the result being a draw or a win for one of the teams.

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 getsw">wwpoints, and the opposing team gets0">00points. If the game results in a draw, both teams getd">ddpoints.

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 playedn">nngames and gotp">pppoints for them.

You have to determine three integersx">xx,y">yyandz">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)(x,y,z), report about it.

Input

The first line contains four integersn">nn,p">pp,w">wwandd">dd(1&#x2264;n&#x2264;1012,0&#x2264;p&#x2264;1017,1&#x2264;d&lt;w&#x2264;105)">(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 thatw&gt;d">w>dw>d, so the number of points awarded for winning is strictly greater than the number of points awarded for draw.

Output

CodeForces-1244C-The Football Season如何巧妙解决比赛胜负问题?

If there is no answer, print&#x2212;1">−1−1.

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

  • x&#x22C5;w+y&#x22C5;d=p">x⋅w+y⋅d=px⋅w+y⋅d=p,
  • x+y+z=n">x+y+z=nx+y+z=n.

Examples

Input

30 60 3 1 Output

17 9 4 Input

10 51 5 4 Output

-1 Input

20 0 15 5 Output

0 0 20

Note

One of the possible answers in the first example —17">1717wins,9">99draws and4">44losses. Then the team got17&#x22C5;3+9&#x22C5;1=60">17⋅3+9⋅1=6017⋅3+9⋅1=60points in17+9+4=30">17+9+4=3017+9+4=30games.

In the second example the maximum possible score is10&#x22C5;5=50">10⋅5=5010⋅5=50. Sincep=51">p=51p=51, there is no answer.

In the third example the team got0">00points, so all20">2020games were lost.

1 #include<stdio.h> 2 #include<algorithm> 3 #include<string.h> 4 using namespace std; 5 typedef long long ll; 6 7 int main() 8 { 9 ll n,p,w,d; 10 scanf("%lld %lld %lld %lld",&n,&p,&w,&d); 11 if(n*w<p) 12 printf("-1\n"); 13 else if(n*w>=p) 14 { 15 if(n*w==p) 16 { 17 printf("%lld 0 0\n",n); 18 } 19 else if(n*w>p) 20 { 21 ll x=p/w; 22 ll q=p%w;; 23 if(q%d==0) 24 { 25 ll y=q/d; 26 if(x+y<=n) 27 printf("%lld %lld %lld",x,y,n-x-y); 28 else 29 printf("-1\n"); 30 } 31 else if(q%d!=0)//说明需要从赢的局数点里面分出一部分点进行补充然后给到平局d 32 { 33 //需要求(q+wi)%d==0 34 int flag=0; 35 for(int i=1; i<=min(x,d); i++) 36 { 37 if((q+w*i)%d==0) 38 { 39 ll xx=x-i; 40 ll yy=(q+w*i)/d; 41 ll zz=n-xx-(q+w*i)/d; 42 if(xx+yy+zz<=n) 43 { 44 flag=1; 45 printf("%lld %lld %lld\n",xx,yy,zz); 46 } 47 else 48 printf("-1\n"); 49 break; 50 } 51 } 52 if(!flag) 53 printf("-1\n"); 54 } 55 } 56 } 57 return 0; 58 }

本文共计1139个文字,预计阅读时间需要5分钟。

CodeForces-1244C-The Football Season如何巧妙解决比赛胜负问题?

The football season has just concluded in Berland. Each match is played between two teams, with the result being a draw or a win for one of the teams.

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 getsw">wwpoints, and the opposing team gets0">00points. If the game results in a draw, both teams getd">ddpoints.

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 playedn">nngames and gotp">pppoints for them.

You have to determine three integersx">xx,y">yyandz">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)(x,y,z), report about it.

Input

The first line contains four integersn">nn,p">pp,w">wwandd">dd(1&#x2264;n&#x2264;1012,0&#x2264;p&#x2264;1017,1&#x2264;d&lt;w&#x2264;105)">(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 thatw&gt;d">w>dw>d, so the number of points awarded for winning is strictly greater than the number of points awarded for draw.

Output

CodeForces-1244C-The Football Season如何巧妙解决比赛胜负问题?

If there is no answer, print&#x2212;1">−1−1.

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

  • x&#x22C5;w+y&#x22C5;d=p">x⋅w+y⋅d=px⋅w+y⋅d=p,
  • x+y+z=n">x+y+z=nx+y+z=n.

Examples

Input

30 60 3 1 Output

17 9 4 Input

10 51 5 4 Output

-1 Input

20 0 15 5 Output

0 0 20

Note

One of the possible answers in the first example —17">1717wins,9">99draws and4">44losses. Then the team got17&#x22C5;3+9&#x22C5;1=60">17⋅3+9⋅1=6017⋅3+9⋅1=60points in17+9+4=30">17+9+4=3017+9+4=30games.

In the second example the maximum possible score is10&#x22C5;5=50">10⋅5=5010⋅5=50. Sincep=51">p=51p=51, there is no answer.

In the third example the team got0">00points, so all20">2020games were lost.

1 #include<stdio.h> 2 #include<algorithm> 3 #include<string.h> 4 using namespace std; 5 typedef long long ll; 6 7 int main() 8 { 9 ll n,p,w,d; 10 scanf("%lld %lld %lld %lld",&n,&p,&w,&d); 11 if(n*w<p) 12 printf("-1\n"); 13 else if(n*w>=p) 14 { 15 if(n*w==p) 16 { 17 printf("%lld 0 0\n",n); 18 } 19 else if(n*w>p) 20 { 21 ll x=p/w; 22 ll q=p%w;; 23 if(q%d==0) 24 { 25 ll y=q/d; 26 if(x+y<=n) 27 printf("%lld %lld %lld",x,y,n-x-y); 28 else 29 printf("-1\n"); 30 } 31 else if(q%d!=0)//说明需要从赢的局数点里面分出一部分点进行补充然后给到平局d 32 { 33 //需要求(q+wi)%d==0 34 int flag=0; 35 for(int i=1; i<=min(x,d); i++) 36 { 37 if((q+w*i)%d==0) 38 { 39 ll xx=x-i; 40 ll yy=(q+w*i)/d; 41 ll zz=n-xx-(q+w*i)/d; 42 if(xx+yy+zz<=n) 43 { 44 flag=1; 45 printf("%lld %lld %lld\n",xx,yy,zz); 46 } 47 else 48 printf("-1\n"); 49 break; 50 } 51 } 52 if(!flag) 53 printf("-1\n"); 54 } 55 } 56 } 57 return 0; 58 }