Description
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.
Sample Input
4 8
4
4 10
2
1 3
0
Sample Output
Hint
In the first sample the author has to get a 2 for all his exams.
In the second sample he should get a 3 for two exams and a 2 for two more.
In the third sample he should get a 3 for one exam.
题解:如果你按2分来算个数肯定很麻烦,经过大佬指点,发现可以这样分析,假设每场考试都得3分,看看比k多多少,多的部分就为得2分的考试场次。
代码如下:
#include<stdio.h>
int main()
{
int a,b;
scanf("%d%d",&a,&b);
if(b/a==2)//只有在2附近才会得出结论,小于2则有不到两分的,大于2平均可以3分以上
printf("%d\n",a-b%a);
else
printf("0\n");
return 0;
}