CF518E.Arthur and Questions
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
After bracket sequences Arthur took up number theory. He has got a new favorite sequence of length n (_a_1, _a_2, ..., a__n), consisting of integers and integer k, not exceeding n.
This sequence had the following property: if you write out the sums of all its segments consisting of k consecutive elements (_a_1 + _a_2 ... + a__k, _a_2 + _a_3 + ... + a__k + 1, ..., a__n - k + 1 + a__n - k + 2 + ... + a__n), then those numbers will form strictly increasing sequence.
For example, for the following sample: n = 5, k = 3, a = (1, 2, 4, 5, 6) the sequence of numbers will look as follows: (1 + 2 + 4, 2 + 4 + 5, 4 + 5 + 6) = (7, 11, 15), that means that sequence a meets the described property.
Obviously the sequence of sums will have n - k + 1 elements.
Somebody (we won't say who) replaced some numbers in Arthur's sequence by question marks (if this number is replaced, it is replaced by exactly one question mark). We need to restore the sequence so that it meets the required property and also minimize the sum |a__i|, where |a__i| is the absolute value of a__i.
在处理完括号序列后,亚瑟开始研究数论。他得到了一个长度为 n 的新喜爱序列 (a1,a2,…,an),其中每个元素均为整数,并给定一个不超过 n 的整数 k。
该序列具有如下性质:若写出所有由 k 个连续元素构成的子段之和(即 a1+a2+⋯+ak,a2+a3+⋯+ak+1,……,an−k+1+an−k+2+⋯+an),则这些和构成一个严格递增的序列。
例如,对如下样例:n=5,k=3,a=(1,2,4,5,6),其子段和序列为:(1+2+4,2+4+5,4+5+6)=(7,11,15),说明序列 a 满足上述性质。
显然,子段和序列共有 n−k+1 个元素。
某人(我们不便透露其身份)将亚瑟序列中的某些数字替换为了问号(若某个数被替换,则恰好被替换成一个问号)。我们需要恢复该序列,使其满足上述性质,并且使 ∑∣ai∣ 最小化,其中 ∣ai∣ 表示 ai 的绝对值。
输入格式
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 105), showing how many numbers are in Arthur's sequence and the lengths of segments respectively.
The next line contains n space-separated elements a__i (1 ≤ i ≤ n).
If a__i = ?, then the i-th element of Arthur's sequence was replaced by a question mark.
Otherwise, a__i ( - 109 ≤ a__i ≤ 109) is the i-th element of Arthur's sequence.
第一行包含两个整数 n 和 k(1≤k≤n≤105),分别表示阿瑟序列中数字的个数以及各段的长度。
第二行包含 n 个以空格分隔的元素 ai(1≤i≤n)。
若 ai= ?,则阿瑟序列的第 i 个元素被替换为一个问号。
否则,ai(−109≤ai≤109)即为阿瑟序列的第 i 个元素。
输出格式
If Arthur is wrong at some point and there is no sequence that could fit the given information, print a single string "Incorrect sequence" (without the quotes).
Otherwise, print n integers — Arthur's favorite sequence. If there are multiple such sequences, print the sequence with the minimum sum |a__i|, where |a__i| is the absolute value of a__i. If there are still several such sequences, you are allowed to print any of them. Print the elements of the sequence without leading zeroes.
如果阿瑟在某个时刻出错,且不存在任何序列能满足给定信息,则输出单个字符串 “Incorrect sequence”(不含引号)。
否则,输出 n 个整数——即阿瑟最喜爱的序列。若存在多个满足条件的序列,则输出所有满足条件的序列中绝对值之和 ∑∣ai∣ 最小的那个序列(其中 ∣ai∣ 表示 ai 的绝对值)。若仍存在多个这样的序列,可任选其一输出。输出序列元素时不得包含前导零。
输入输出样例
输入#1
3 2 ? 1 2
输出#1
0 1 2
输入#2
5 1 -10 -9 ? -7 -6
输出#2
-10 -9 -8 -7 -6
输入#3
5 3 4 6 7 2 9
输出#3
Incorrect sequence
输入解题思路,AI测评打分。不知道怎么写?