#abc281d. D - Max Multiple
D - Max Multiple
Score : points
问题描述
你给定一个非负整数序列 。
令 为可以表示为 中(具有不同下标的) 个项之和的所有非负整数集合。
找出 中最大的 的倍数。如果 中不存在 的倍数,则输出 -1
。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a sequence of non-negative integers .
Let be the set of non-negative integers that can be the sum of terms in (with distinct indices).
Find the greatest multiple of in . If there is no multiple of in , print -1
instead.
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
4 2 2
1 2 3 4
Sample Output 1
6
Here are all the ways to choose two terms in .
- Choose and , whose sum is .
- Choose and , whose sum is .
- Choose and , whose sum is .
- Choose and , whose sum is .
- Choose and , whose sum is .
- Choose and , whose sum is .
Thus, we have . The greatest multiple of in is , so you should print .
Sample Input 2
3 1 2
1 3 5
Sample Output 2
-1
In this example, we have . Nothing in is a multiple of , so you should print -1
.
update @ 2024/3/10 11:48:20
相关
在以下作业中: