codeforce_Diplomas and Certificates_水
2017-08-17 16:26
387 查看
A. Diplomas and Certificates
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 be exactly 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
看案例,观察
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 be exactly 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
看案例,观察
#include<iostream> #include<cstdio> #include<cstring> #include<map> #include<algorithm> using namespace std; typedef long long ll; int main() { ll n ,k; while(cin>>n>>k) { ll t=n/2; if(k>=t) cout<<"0 0 "<<n<<endl; else { ll s1=t/(k+1); ll s2=s1*k; ll s3=n-s1-s2; cout<<s1<<" "<<s2<<" "<<s3<<endl; } } return 0; }
相关文章推荐
- codeforce Ilya and Roads (区间dp)
- codeforce C. Valera and Elections (DFS)
- codeforce 510C Fox And Names (拓扑排序)
- codeforce 766D Mahmoud and a Dictionary 带权并查集
- Codeforce - 573B - Bear and Blocks
- codeforce 66E - Petya and Post(dp+减少冗余)
- codeforce B. Petya and Exam
- codeforce 766D Mahmoud and a Dictionary 带权并查集
- codeforce 66E - Petya and Post(dp+减少冗余)
- codeforce Anton and Classes
- ACM刷题之codeforce————Arpa and a research in Mexican wave
- codeforce 766D Mahmoud and a Dictionary 带权并查集
- codeforce 793 B Igor and his way to work
- CodeForce 508C Anya and Ghosts (贪心+模拟)
- codeforce 559 C Gerald and Giant Chess
- codeforce C - Vasya and Robot
- codeforce之Bear and Two Paths
- coderforce A.Ilya and Diplomas
- code force A. Bear and Five Cards&B. Bear and Finding Criminals
- code force. Anton and fairy tale.