atcoder#ARC150F. [ARC150F] Constant Sum Subsequence
[ARC150F] Constant Sum Subsequence
Score : points
Problem Statement
We have a sequence of positive integers of length , , and a positive integer . For this sequence of positive integers, holds for positive integers , and only are given as the input.
Find the minimum integer such that every sequence of positive integers totaling is a (not necessarily contiguous) subsequence of the sequence of positive integers.
It can be shown that at least one such exists under the Constraints of this problem.
Constraints
- For every positive integer , contains at least one occurrence of .
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
6 4
1 1 2 1 4 3
9
There are eight sequences to consider: $B=(1,\ 1,\ 1,\ 1),\ (1,\ 1,\ 2),\ (1,\ 2,\ 1),\ (1,\ 3),\ (2,\ 1,\ 1),\ (2,\ 2),\ (3,\ 1),\ (4)$.
For , for instance, is not a subsequence of $(A_1,A_2,\ \dots,\ A_8)=(1,\ 1,\ 2,\ 1,\ 4,\ 3,\ 1,\ 1)$.
For , on the other hand, every is a subsequence of $(A_1,A_2,\ \dots,\ A_9)=(1,\ 1,\ 2,\ 1,\ 4,\ 3,\ 1,\ 1,\ 2)$.
14 5
1 1 1 2 3 1 2 4 5 1 1 2 3 1
11
19 10
1 6 2 7 4 8 5 9 1 10 4 1 3 1 3 2 2 2 1
39