Educational Codeforces Round 24 A

There are n students who have taken part in an olympiad. Now it's time to award the students.

Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must beexactly k times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of n). It's possible that there are no winners.

You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners.

Input

The first (and the only) line of input contains two integers n and k (1 ≤ n, k ≤ 1012), where n is the number of students and k is the ratio between the number of certificates and the number of diplomas.

Output

Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible.

It's possible that there are no winners.

Examples
input
18 2
output
3 6 9
input
9 10
output
0 0 9
input
1000000000000 5
output
83333333333 416666666665 500000000002
input
1000000000000 499999999999
output
1 499999999999 500000000000

题意:有n个人参赛,必须保证获奖A的人数是获奖B的k倍,获奖人数不得超过总数的1/2,并输出未获奖人数
解法:
1 都没获奖的情况 即获奖A为1人,获奖B为k人,一共为1+k,但大于num/2
2 接下来的获奖情况 获奖A为x人,那么获奖B为xk人,一共x(1+k)==num
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     long long n;
 6     long long k;
 7     cin>>n>>k;
 8     long long num=n/2;
 9     long long sum=0;
10     if(1+k>num)
11     {
12         cout<<"0 0 "<<n<<endl;
13     }
14     else
15     {
16        long long x=num/(1+k);
17 
18        cout<<x<<" "<<x*k<<" "<<n-(x+x*k)<<endl;
19     }
20     return 0;
21 }
原文地址:https://www.cnblogs.com/yinghualuowu/p/7134439.html