시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
0.4 초 | 1024 MB | 148 | 52 | 43 | 35.537% |
You are given two positive integers n, m and two sequences of positive integers A and B. The sequence A consists of n elements, each one in the interval [1, m], while the sequence B consists of m elements, each one in the interval [1, n].
Write a program, which finds a nonempty subsequence of A and a nonempty subsequence of B, which have equal sums of elements.
Definition: For a sequence C = C0, C1, …, Cp, a subsequence of C is a sequence of elements Ci1, Ci2, …, Cik of C for which 0 ≤ i1 < i2 < ...< ik ≤ p.
From the first line of the standard input, your program reads a positive integer n – the size of sequence A. From the second line, your program reads n positive integers – the elements of A. From the third line of the standard input, your program reads a positive integer m – the size of sequence B. From the fourth line, your program reads m positive integers – the elements of B.
On the first line of the standard output, your program should print a positive integer p – the size of the chosen subsequence of A. On the second line, your program should print p integers – the indices of the chosen elements from A. On the third line of the standard output, your program should print a positive integer q – the size of the chosen subsequence of B. On the fourth line, your program should print q integers – the indices of the chosen elements from B.
Attention: Indices start from 0. The order in which your program prints the chosen indices doesn’t matter. It is guaranteed that at least one solution exists. If more than one solution exists, print any one of them.
번호 | 배점 | 제한 |
---|---|---|
1 | 10 | n, m ≤ 20 |
2 | 25 | n, m ≤ 300 |
3 | 65 | No additional constraints. |
5 2 3 3 2 3 3 4 5 5
3 1 2 4 2 0 1
a[1] + a[2] + a[4] = 3 + 3 + 3 = 9
b[0] + b[1] = 4 + 5 = 9.
Another possible solution is: a[2] +a[3] = 3 + 2 = 5 = b[1].