123456789 Points
InterviewTime limit0.2sMemory limit512 MB
Given N notes and a target score S, find counts of Perfect, Great, Good judgments giving exactly S, or report -1.
- Level
Medium6 of 10
- Topics
- Math, Binary search, Implementation, Number theory
- Solved
- No attempts yet
Problem
Itchangmyeong plays a rhythm game as a hobby. Hitting notes that fall from the top with accurate timing earns a high score.
Each note that is hit receives one of the following judgments.
- Perfect
- Great
- Good
- Miss
A note that is not hit receives a Miss judgment. There are no judgments other than these four. In a song with N notes, the score when a Perfect, b Great, and c Good judgments are received is computed by the following formula. The fractional part is discarded.
In other words, taking the Good judgment score as the base, the score of each judgment is as follows.
- Perfect = 2 Good + 1
- Great = 2 Good
- Good = 1 Good
- Miss = 0
For example, in a song with 100 notes, receiving 10 Perfect, 20 Great, and 30 Good judgments earns 450,000,010 points. The maximum score in this case is 109+N points, obtained by receiving Perfect judgments on all N notes.
Itchangmyeong wants to earn exactly 123,456,789 points in this game and surprise people. Itchangmyeong is a top-tier player, so he can set the judgment of every note as he likes. Given the number of notes in the song he is going to play, write a program that computes how he should play the song to earn the score he wants.
Input
The first line gives the number of test cases T (1 ≤ T ≤ 2,000). The next lines give T test cases.
In each test case, one line gives the number of notes N (1 ≤ N ≤ 20,000) and the score S (0 ≤ S ≤ 109+N) that Itchangmyeong wants, separated by a space. N and S are integers.
Output
For each test case, output the following on one line.
- If Itchangmyeong can earn exactly S points by receiving a Perfect, b Great, and c Good judgments, output 2a+2b+c and a separated by a space. No input has more than one possible pair (2a+2b+c, a).
- If Itchangmyeong cannot earn exactly S points no matter how he plays the song, output
-1.