A8650 | Exams
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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$ .
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$ .
输入格式
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$ .
It is guaranteed that there exists a way to pass $n$ exams in the way that makes the sum of marks equal exactly $k$ .
输出格式
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$ .
输入输出样例
输入 #1
4 8
输出 #1
4
输入 #2
4 10
输出 #2
2
输入 #3
1 3
输出 #3
0
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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted