Once upon a time, there was an onsite programming contest, which had attracted many teams to participate in. However, different teams had a different billing standard. In general, there were three types of teams:
- Teams of Type A could participate in the contest for free.
- Teams of Type B had to pay 1000 dollars for the expenses for board and lodging.
- Teams of Type C had to pay 1000 dollars for the expenses for board and lodging and 1500 dollars for entry fee.
Finally the contest was held successfully with x x x teams in total participating in, and the host had earned y y y dollars. However, the details about the number of teams of each type had vanished. Now Walk Alone wants to restore the details using x x x and y y y.
Input
The only line of input contains two integers x x x and y ( 0 ≤ x ≤ 1 0 6 , 0 ≤ y ≤ 1 0 9 ) y (0≤x≤10^6, 0≤y≤10^9) y(0≤x≤106,0≤y≤109), denoting the number of teams in total and the total amount of money the host had earned.
Output
If there’s a way to construct the number three types of teams satisfying the condition above, output three integers A , B , C A,B,C A,B,C to denote the number of teams of type A, B and C. You need to guarantee that 0 ≤ A , B , C 0≤A,B,C 0≤A,B,C. If there are multiple ways, output any of them.
If there’s no answer satisfying the condition above, output −1 instead.
Examples
input800 1500000
output
200 0 600
input
0 0
output
0 0 0
input
500 100
output
-1
Note
For the first sample test case you can also output 50 50 50 250 250 250 500 500 500, which can also satisfy the condition above.
For the second sample test case, there’s nobody who needs to bill participating in the contest, so no money can be earned by the host.
For the third sample test case, the host cannot earn such little money. So output −1.
题目大意:
给定总队伍数 x x x 即 ( a + b + c ) (a+b+c) (a+b+c) 和主办方收到的金钱数 y y y,如何分配3种队伍 a , b , c a, b, c a,b,c 的数量,恰好使得总金钱数为 y y y。
解题思路:
其实就是尽量把 y y y 分完。特别的是要知道可以把已经分给 C 的拿出来加上 B 分剩下的还能不能再分完(啥也不剩的那种)若能恰好分完,则输出对应队伍数的分配;若不能,则输出 − 1 -1 −1。
(虽然还有些情况没考虑上,但是能过 😃 )
#include <bits/stdc++.h>
using namespace std;
const int costB = 1000, costC = 2500;
int main()
{
int x, y; cin>>x>>y;
int c = y/costC;
y %= costC;
int b = y/costB;
if(y%costB) //看队伍B有无剩余(或者队伍C有没有选完)
{
if(y%costB==500 && c) //有剩余就看能不能把队伍C拆一个过来
{
c--, b += 3; //500+2500
cout<<x-b-c<<' '<<b<<' '<<c;
}
else cout<<-1;
}
else cout<<x-b-c<<' '<<b<<' '<<c;
return 0;
}