P7383 "EZEC-6" Addition and Subtraction
Description
You are given two numbers $n, m$. You need to split $m$ into $n$ **distinct positive integers** (that is, the sum of these $n$ numbers is $m$), such that within the interval $[1, m]$, there is at least one positive integer that cannot be obtained by adding and subtracting these $n$ numbers (each number can be used at most once in the adding/subtracting process).
That is, let the $i$-th number among the $n$ positive integers be $a_i$. You need to ensure that within $[1, m]$, there exists at least one positive integer that cannot be represented in the form $\sum\limits^{n}_{i=1} k_i \times a_i \ (k_i \in \{-1, 0, 1\})$.
If there is no solution, output `-1`.
If there is a solution, output any set of $n$ positive integers that meets the requirement, and also output any number in $[1, m]$ that cannot be represented.
Input Format
**This problem has multiple test cases.**
The first line contains a positive integer $T$, the number of test cases.
For each test case, one line contains two positive integers $n, m$.
Output Format
For each test case:
If there is no solution, output one line `-1`.
If there is a solution, output $n$ positive integers in the first line, representing a valid solution, and output one positive integer in $[1, m]$ in the second line. This integer cannot be represented.
Explanation/Hint
**This problem uses bundled tests.**
- Subtask 1 (10 points): $n \le 2$.
- Subtask 2 (20 points): $2n^2 \le m$.
- Subtask 3 (20 points): $\lceil 1.5n^2 \rceil \le m$.
- Subtask 4 (20 points): $n \le 5$.
- Subtask 5 (30 points): no special constraints.
Constraints: For $100\%$ of the testdata, $1 \le T \le 100$, $1 \le n, m \le 10^4$.
Translated by ChatGPT 5