The Battle of Giants
InterviewTime limit1sMemory limit512 MB
Given a final score a:b, decide whether it can result from matches worth 3 points for a win and 1 for a draw, and if so print win, draw, win counts using the fewest matches.
- Level
Medium5 of 10
- Topics
- Math, Greedy, Implementation
- Solved
- No attempts yet
Problem
A famous programming contest organizer decided to hold a champions' competition called "The Battle of Giants". Two teams compete in the battle. Several matches are organized for the competition.
Each match can end with a win for one of the teams, or with a draw. When a team wins the match it scores 3 points, and the opposite team scores no point. In the case of a draw, teams score 1 point each. After all the matches end, the final score : is calculated: and are the number of points scored by the first and second team, respectively.
For example, if the first match is won by the first team, the second match ended with a draw, and the third match is also won by the first team, the final score is 7:1.
You are given the final score. Find out whether the given score is possible, and what the minimum number of matches could be. Print the number of matches won by the first team, the number of matches ended with a draw, and the number of matches won by the second team.
Input
The first line contains a single integer , the number of points scored by the first team.
The second line contains a single integer , the number of points scored by the second team.
The given and are nonnegative and don't exceed .
Output
If the given final score isn't possible, print .
Otherwise, print three integers: the number of matches won by the first team, the number of matches ended with a draw, and the number of matches won by the second team, respectively. Find any solution with the minimum number of matches played.