CF1358E.Are You Fired?
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Levian works as an accountant in a large company. Levian knows how much the company has earned in each of the n consecutive months — in the i-th month the company had income equal to ai (positive income means profit, negative income means loss, zero income means no change). Because of the general self-isolation, the first ⌈2n⌉ months income might have been completely unstable, but then everything stabilized and for the last ⌊2n⌋ months the income was the same.
Levian decided to tell the directors n−k+1 numbers — the total income of the company for each k consecutive months. In other words, for each i between 1 and n−k+1 he will say the value ai+ai+1+…+ai+k−1. For example, if a=[−1,0,1,2,2] and k=3 he will say the numbers 0,3,5.
Unfortunately, if at least one total income reported by Levian is not a profit (income ≤0), the directors will get angry and fire the failed accountant.
Save Levian's career: find any such k, that for each k months in a row the company had made a profit, or report that it is impossible.
莱维安是一家大型公司的会计。莱维安知道公司在连续 n 个月中每个月的收入——第 i 个月公司的收入为 ai(正收入表示盈利,负收入表示亏损,零收入表示无变化)。由于普遍实行居家隔离,前 ⌈2n⌉ 个月的收入可能完全不稳定;但随后情况趋于稳定,在最后 ⌊2n⌋ 个月中,每月收入均相同。
莱维安决定向公司董事报告 n−k+1 个数字——即公司每连续 k 个月的总收入。换言之,对每个 i(1≤i≤n−k+1),他将报告数值 ai+ai+1+…+ai+k−1。例如,若 a=[−1,0,1,2,2] 且 k=3,则他将报告数字 0,3,5。
不幸的是,如果莱维安报告的任意一个总收入非盈利(即收入 ≤0),董事们便会发怒并解雇这位失职的会计。
请挽救莱维安的职业生涯:找出任意一个满足条件的 k,使得公司任意连续 k 个月的总收入均为盈利;若不存在这样的 k,则报告其不可能性。
输入格式
The first line contains a single integer n (2≤n≤5⋅105) — the number of months for which Levian must account.
The second line contains ⌈2n⌉ integers a1,a2,…,a⌈2n⌉, where ai (−109≤ai≤109) — the income of the company in the i-th month.
Third line contains a single integer x (−109≤x≤109) — income in every month from ⌈2n⌉+1 to n.
第一行包含一个整数 n(2≤n≤5⋅105)—— Levian 需要记账的月份数。
第二行包含 ⌈2n⌉ 个整数 a1,a2,…,a⌈2n⌉,其中 ai(−109≤ai≤109)表示公司第 i 个月的收入。
第三行包含一个整数 x(−109≤x≤109)—— 表示从第 ⌈2n⌉+1 个月到第 n 个月,每个月的收入均为 x。
输出格式
In a single line, print the appropriate integer k or −1, if it does not exist.
If there are multiple possible answers, you can print any.
在一行中输出合适的整数 k,如果不存在则输出 −1。
如果存在多个可能的答案,你可以输出其中任意一个。
输入输出样例
输入#1
3 2 -1 2
输出#1
2
输入#2
5 2 2 -8 2
输出#2
-1
输入#3
6 -2 -2 6 -1
输出#3
4
说明/提示
In the first example, k=2 and k=3 satisfy: in the first case, Levian will report the numbers 1,1, and in the second case — one number 3.
In the second example, there is no such k.
In the third example, the only answer is k=4: he will report the numbers 1,2,3.
在第一个例子中,k=2 和 k=3 均满足条件:在第一种情况下,Levian 将报告数字 1,1;在第二种情况下,他将报告一个数字 3。
在第二个例子中,不存在满足条件的 k。
在第三个例子中,唯一解为 k=4:他将报告数字 1,2,3。
输入解题思路,AI测评打分。不知道怎么写?