A8329 | Two progressions
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
An arithmetic progression is such a non-empty sequence of numbers where the difference between any two successive numbers is constant. This constant number is called common difference. For example, the sequence 3, 7, 11, 15 is an arithmetic progression. The definition implies that any sequences whose length equals 1 or 2 are arithmetic and all sequences whose length equals 0 are non-arithmetic.
You are given a sequence of different integers $a_{1},a_{2},...,a_{n}$ . You should either split it into two arithmetic progressions or find out that the operation is impossible to perform. Splitting assigns each member of the given sequence to one of two progressions, but the relative order of numbers does not change. Splitting is an inverse operation to merging.
You are given a sequence of different integers $a_{1},a_{2},...,a_{n}$ . You should either split it into two arithmetic progressions or find out that the operation is impossible to perform. Splitting assigns each member of the given sequence to one of two progressions, but the relative order of numbers does not change. Splitting is an inverse operation to merging.
输入格式
The first line contains a positive integer $n$ ( $2<=n<=30000$ ), $n$ is the length of the given sequence. The second line contains elements of the given sequence $a_{1},a_{2},...,a_{n}$ ( $-10^{8}<=a_{i}<=10^{8}$ ). The elements of the progression are different integers.
输出格式
Print the required arithmetic progressions, one per line. The progressions can be positioned in any order. Each progression should contain at least one number. If there's no solution, then print "No solution" (without the quotes)in the only line of the input file. If there are several solutions, print any of them.
输入输出样例
输入 #1
6 4 1 2 7 3 10
输出 #1
1 2 3 4 7 10
输入 #2
5 1 2 3 -2 -7
输出 #2
1 2 3 -2 -7
In the second sample another solution is also possible (number three can be assigned to the second progression): 1, 2 and 3, -2, -7.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted