#arc178c. C - Sum of Abs 2
C - Sum of Abs 2
Score : points
问题陈述
给定正整数 和 ,以及长度为 的正整数序列 。
对于每个 ,回答以下问题:
确定是否存在一个非负整数序列 ,使得 $\displaystyle \sum_{j = 1} ^ {L - 1} \sum_{k = j + 1} ^ {L} |B_{j} - B_{k}| = A_{i}$。如果存在,找到这样的序列 的 的最小值。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given positive integers and , and a sequence of positive integers of length .
For each , answer the following question:
Determine if there exists a sequence of non-negative integers such that $\displaystyle \sum_{j = 1} ^ {L - 1} \sum_{k = j + 1} ^ {L} |B_{j} - B_{k}| = A_{i}$. If it exists, find the minimum value of for such a sequence .
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain -1
if no sequence satisfies the condition for ; otherwise, it should contain the minimum value of for such a sequence .
Sample Input 1
2 4
10 5
Sample Output 1
3
-1
For , if we take , then $\displaystyle \sum_{j = 1} ^ {L - 1} \sum_{k = j + 1} ^ {L} |B_{j} - B_{k}| = 10$, where . No non-negative integer sequence satisfies the condition with , so print in the first line.
For , there is no non-negative integer sequence that satisfies the condition, so print -1
in the second line.
Sample Input 2
6 8
167 924 167167 167924 116677 154308
Sample Output 2
11
58
10448
10496
7293
9645