CF1546A.AquaMoon and Two Arrays
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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≤i,j≤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 ai−1 and aj+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 ai=bi for all 1≤i≤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.
AquaMoon 和 Cirno 正在玩一个关于数组的有趣游戏。Cirno 准备了两个数组 a 和 b,它们均包含 n 个非负整数。AquaMoon 可以执行以下操作任意多次(也可以不执行):
- 她选择两个下标 i 和 j(满足 1≤i,j≤n),然后将数组 a 的第 i 个元素减 1,并将数组 a 的第 j 个元素加 1。操作后,数组 a 在第 i 个和第 j 个位置上的值分别为 ai−1 和 aj+1。每次操作后,数组 a 的每个元素都必须保持为非负数。若 i=j,该操作不会改变数组 a。
AquaMoon 希望通过若干次操作使得数组 a 和 b 相等。当且仅当对所有 1≤i≤n 均有 ai=bi 时,称两个数组 a 和 b 相等。
请帮助 AquaMoon 找出一组能实现目标的操作序列;若无法使数组 a 和 b 相等,则判定其不可能。
请注意:你无需最小化操作次数。
输入格式
The input consists of multiple test cases. The first line contains a single integer t (1≤t≤100) — the number of test cases.
The first line of each test case contains a single integer n (1≤n≤100).
The second line of each test case contains n integers a1,a2,…,an (0≤ai≤100). The sum of all ai does not exceed 100.
The third line of each test case contains n integers b1,b2,…,bn (0≤bi≤100). The sum of all bi does not exceed 100.
输入包含多个测试用例。第一行包含一个整数 t(1≤t≤100),表示测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤100)。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(0≤ai≤100)。所有 ai 的总和不超过 100。
每个测试用例的第三行包含 n 个整数 b1,b2,…,bn(0≤bi≤100)。所有 bi 的总和不超过 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≤m≤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≤100.
If there are multiple possible solutions, you can print any.
对于每个测试用例,如果无法通过若干次操作使两个数组相等,则在唯一的一行中输出 -1。
否则,在第一行输出一个整数 m(0≤m≤100)—— 表示操作次数。随后输出 m 行,每行包含两个整数 i 和 j —— 表示该次操作所选择的下标。
可以证明:若存在某种操作序列能使两个数组相等,则必存在一个满足 m≤100 的操作序列。
若存在多种可行解,输出任意一种即可。
输入输出样例
输入#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]→[2,1,3,4];
- i=3, j=1: [2,1,3,4]→[3,1,2,4];
In the second example, it's impossible to make two arrays equal.
在第一个例子中,我们执行以下操作:
- i=2,j=1:[1,2,3,4]→[2,1,3,4];
- i=3,j=1:[2,1,3,4]→[3,1,2,4];
在第二个例子中,无法使两个数组相等。
输入解题思路,AI测评打分。不知道怎么写?