A14869 | Vasya and Coins
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Vasya decided to go to the grocery store. He found in his wallet $a$ coins of $1$ burle and $b$ coins of $2$ burles. He does not yet know the total cost of all goods, so help him find out $s$ ( $s > 0$ ): the minimum positive integer amount of money he cannot pay without change or pay at all using only his coins.
For example, if $a=1$ and $b=1$ (he has one $1$ -burle coin and one $2$ -burle coin), then:
- he can pay $1$ burle without change, paying with one $1$ -burle coin,
- he can pay $2$ burle without change, paying with one $2$ -burle coin,
- he can pay $3$ burle without change by paying with one $1$ -burle coin and one $2$ -burle coin,
- he cannot pay $4$ burle without change (moreover, he cannot pay this amount at all).
So for $a=1$ and $b=1$ the answer is $s=4$ .
For example, if $a=1$ and $b=1$ (he has one $1$ -burle coin and one $2$ -burle coin), then:
- he can pay $1$ burle without change, paying with one $1$ -burle coin,
- he can pay $2$ burle without change, paying with one $2$ -burle coin,
- he can pay $3$ burle without change by paying with one $1$ -burle coin and one $2$ -burle coin,
- he cannot pay $4$ burle without change (moreover, he cannot pay this amount at all).
So for $a=1$ and $b=1$ the answer is $s=4$ .
输入格式
The first line of the input contains an integer $t$ ( $1 \le t \le 10^4$ ) — the number of test cases in the test.
The description of each test case consists of one line containing two integers $a_i$ and $b_i$ ( $0 \le a_i, b_i \le 10^8$ ) — the number of $1$ -burle coins and $2$ -burles coins Vasya has respectively.
The description of each test case consists of one line containing two integers $a_i$ and $b_i$ ( $0 \le a_i, b_i \le 10^8$ ) — the number of $1$ -burle coins and $2$ -burles coins Vasya has respectively.
输出格式
For each test case, on a separate line print one integer $s$ ( $s > 0$ ): the minimum positive integer amount of money that Vasya cannot pay without change or pay at all.
输入输出样例
输入 #1
5 1 1 4 0 0 2 0 0 2314 2374
输出 #1
4 5 1 1 7063
- The first test case of the example is clarified into the main part of the statement.
- In the second test case, Vasya has only $1$ burle coins, and he can collect either any amount from $1$ to $4$ , but $5$ can't.
- In the second test case, Vasya has only $2$ burle coins, and he cannot pay $1$ burle without change.
- In the fourth test case you don't have any coins, and he can't even pay $1$ burle.
- In the second test case, Vasya has only $1$ burle coins, and he can collect either any amount from $1$ to $4$ , but $5$ can't.
- In the second test case, Vasya has only $2$ burle coins, and he cannot pay $1$ burle without change.
- In the fourth test case you don't have any coins, and he can't even pay $1$ burle.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted