A. Exams
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
One day the Codeforces round author sat exams. He had n exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend too much time and effort to make the sum of his marks strictly more than k. That could have spoilt the Codeforces round. On the other hand, if the sum of his marks is strictly less than k, the author’s mum won’t be pleased at all.
The Codeforces authors are very smart and they always get the mark they choose themselves. Also, the Codeforces authors just hate re-sitting exams.
Help the author and find the minimum number of exams he will have to re-sit if he passes the exams in the way that makes the sum of marks for all n exams equal exactly k.
Input
The single input line contains space-separated integers n and k (1 ≤ n ≤ 50, 1 ≤ k ≤ 250) — the number of exams and the required sum of marks.
It is guaranteed that there exists a way to pass n exams in the way that makes the sum of marks equal exactly k.
Output
Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal k.
Examples
input
4 8
output
4
input
4 10
output
2
input
1 3
output
0
My Answer Code:
/*
Author:Albert Tesla Wizard
Time:2020/11/16
*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,k,ans;
cin>>n>>k;
if(k/n>2)ans=0;
else if(k%n==0&&k/n==2)ans=n;
else if(k%n>0&&k/n==2)for(int i=1;i<=n;i++)if((k-i*2)/(n-i)>2){ans=i;break;}
cout<<ans<<'\n';
return 0;
}
博客内容涉及到一个关于考试策略的问题,作者需要在参加n场考试并确保总分等于k的情况下,尽可能少地得到2分。代码展示了如何通过计算找出最少得2分的考试次数。输入包括考试数量n和目标总分k,输出为最少需要重考的次数。示例展示了不同情况下的输出结果。
397

被折叠的 条评论
为什么被折叠?



