A14445 | AquaMoon and Two Arrays
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
AquaMoon and Cirno are playing an interesting game with arrays. Cirno has prepared two arrays $a$ and $b$ , both consist of $n$ non-negative integers. AquaMoon can perform the following operation an arbitrary number of times (possibly zero):
- She chooses two indices $i$ and $j$ ( $1 \le i, j \le n$ ), then decreases the $i$ -th element of array $a$ by $1$ , and increases the $j$ -th element of array $a$ by $1$ . The resulting values at $i$ -th and $j$ -th index of array $a$ are $a_i - 1$ and $a_j + 1$ , respectively. Each element of array $a$ must be non-negative after each operation. If $i = j$ this operation doesn't change the array $a$ .
AquaMoon wants to make some operations to make arrays $a$ and $b$ equal. Two arrays $a$ and $b$ are considered equal if and only if $a_i = b_i$ for all $1 \leq i \leq n$ .
Help AquaMoon to find a sequence of operations that will solve her problem or find, that it is impossible to make arrays $a$ and $b$ equal.
Please note, that you don't have to minimize the number of operations.
- She chooses two indices $i$ and $j$ ( $1 \le i, j \le n$ ), then decreases the $i$ -th element of array $a$ by $1$ , and increases the $j$ -th element of array $a$ by $1$ . The resulting values at $i$ -th and $j$ -th index of array $a$ are $a_i - 1$ and $a_j + 1$ , respectively. Each element of array $a$ must be non-negative after each operation. If $i = j$ this operation doesn't change the array $a$ .
AquaMoon wants to make some operations to make arrays $a$ and $b$ equal. Two arrays $a$ and $b$ are considered equal if and only if $a_i = b_i$ for all $1 \leq i \leq n$ .
Help AquaMoon to find a sequence of operations that will solve her problem or find, that it is impossible to make arrays $a$ and $b$ equal.
Please note, that you don't have to minimize the number of operations.
输入格式
The input consists of multiple test cases. The first line contains a single integer $t$ ( $1 \leq t \leq 100$ ) — the number of test cases.
The first line of each test case contains a single integer $n$ ( $1 \leq n \leq 100$ ).
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ( $0 \leq a_i \leq 100$ ). The sum of all $a_i$ does not exceed $100$ .
The third line of each test case contains $n$ integers $b_1, b_2, \dots, b_n$ ( $0 \leq b_i \leq 100$ ). The sum of all $b_i$ does not exceed $100$ .
The first line of each test case contains a single integer $n$ ( $1 \leq n \leq 100$ ).
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ( $0 \leq a_i \leq 100$ ). The sum of all $a_i$ does not exceed $100$ .
The third line of each test case contains $n$ integers $b_1, b_2, \dots, b_n$ ( $0 \leq b_i \leq 100$ ). The sum of all $b_i$ does not exceed $100$ .
输出格式
For each test case print "-1" on the only line if it is impossible to make two arrays equal with some sequence of operations.
Otherwise, print an integer $m$ ( $0 \leq m \leq 100$ ) in the first line — the number of operations. Then print $m$ lines, each line consists of two integers $i$ and $j$ — the indices you choose for the operation.
It can be proven that if it is possible to make two arrays equal with some sequence of operations, there exists a sequence with $m \leq 100$ .
If there are multiple possible solutions, you can print any.
Otherwise, print an integer $m$ ( $0 \leq m \leq 100$ ) in the first line — the number of operations. Then print $m$ lines, each line consists of two integers $i$ and $j$ — the indices you choose for the operation.
It can be proven that if it is possible to make two arrays equal with some sequence of operations, there exists a sequence with $m \leq 100$ .
If there are multiple possible solutions, you can print any.
输入输出样例
输入 #1
4 4 1 2 3 4 3 1 2 4 2 1 3 2 1 1 0 0 5 4 3 2 1 0 0 1 2 3 4
输出 #1
2 2 1 3 1 -1 0 6 1 4 1 4 1 5 1 5 2 5 2 5
In the first example, we do the following operations:
- $i = 2$ , $j = 1$ : $[1, 2, 3, 4] \rightarrow [2, 1, 3, 4]$ ;
- $i = 3$ , $j = 1$ : $[2, 1, 3, 4] \rightarrow [3, 1, 2, 4]$ ;
In the second example, it's impossible to make two arrays equal.
- $i = 2$ , $j = 1$ : $[1, 2, 3, 4] \rightarrow [2, 1, 3, 4]$ ;
- $i = 3$ , $j = 1$ : $[2, 1, 3, 4] \rightarrow [3, 1, 2, 4]$ ;
In the second example, it's impossible to make two arrays equal.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted