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
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.
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.
OutputOutput 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 input18 2output
3 6 9input
9 10output
0 0 9input
1000000000000 5output
83333333333 416666666665 500000000002input
1000000000000 499999999999output
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 }
Educational Codeforces Round 24 A