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 nn consecutive months — in the ii-th month the company had income equal to aia_i (positive income means profit, negative income means loss, zero income means no change). Because of the general self-isolation, the first ⌈n2⌉\lceil \tfrac{n}{2} \rceil months income might have been completely unstable, but then everything stabilized and for the last ⌊n2⌋\lfloor \tfrac{n}{2} \rfloor months the income was the same.

Levian decided to tell the directors n−k+1n-k+1 numbers — the total income of the company for each kk consecutive months. In other words, for each ii between 11 and n−k+1n-k+1 he will say the value ai+ai+1+…+ai+k−1a_i + a_{i+1} + \ldots + a_{i + k - 1}. For example, if a=[−1,0,1,2,2]a=[-1, 0, 1, 2, 2] and k=3k=3 he will say the numbers 0,3,50, 3, 5.

Unfortunately, if at least one total income reported by Levian is not a profit (income ≤0\le 0), the directors will get angry and fire the failed accountant.

Save Levian's career: find any such kk, that for each kk months in a row the company had made a profit, or report that it is impossible.

莱维安是一家大型公司的会计。莱维安知道公司在连续 nn 个月中每个月的收入——第 ii 个月公司的收入为 aia_i(正收入表示盈利,负收入表示亏损,零收入表示无变化)。由于普遍实行居家隔离,前 ⌈n2⌉\lceil \tfrac{n}{2} \rceil 个月的收入可能完全不稳定;但随后情况趋于稳定,在最后 ⌊n2⌋\lfloor \tfrac{n}{2} \rfloor 个月中,每月收入均相同。

莱维安决定向公司董事报告 n−k+1n-k+1 个数字——即公司每连续 kk 个月的总收入。换言之,对每个 ii(1≤i≤n−k+11 \le i \le n-k+1),他将报告数值 ai+ai+1+…+ai+k−1a_i + a_{i+1} + \ldots + a_{i + k - 1}。例如,若 a=[−1,0,1,2,2]a=[-1, 0, 1, 2, 2] 且 k=3k=3,则他将报告数字 0,3,50, 3, 5。

不幸的是,如果莱维安报告的任意一个总收入非盈利(即收入 ≤0\le 0),董事们便会发怒并解雇这位失职的会计。

请挽救莱维安的职业生涯:找出任意一个满足条件的 kk,使得公司任意连续 kk 个月的总收入均为盈利;若不存在这样的 kk,则报告其不可能性。

输入格式

The first line contains a single integer nn (2≤n≤5⋅1052 \le n \le 5\cdot 10^5) — the number of months for which Levian must account.

The second line contains ⌈n2⌉\lceil{\frac{n}{2}}\rceil integers a1,a2,…,a⌈n2⌉a_1, a_2, \ldots, a_{\lceil{\frac{n}{2}}\rceil}, where aia_i (−109≤ai≤109-10^9 \le a_i \le 10^9) — the income of the company in the ii-th month.

Third line contains a single integer xx (−109≤x≤109-10^9 \le x \le 10^9) — income in every month from ⌈n2⌉+1\lceil{\frac{n}{2}}\rceil + 1 to nn.

第一行包含一个整数 nn(2≤n≤5⋅1052 \le n \le 5\cdot 10^5)—— Levian 需要记账的月份数。

第二行包含 ⌈n2⌉\lceil{\frac{n}{2}}\rceil 个整数 a1,a2,…,a⌈n2⌉a_1, a_2, \ldots, a_{\lceil{\frac{n}{2}}\rceil},其中 aia_i(−109≤ai≤109-10^9 \le a_i \le 10^9)表示公司第 ii 个月的收入。

第三行包含一个整数 xx(−109≤x≤109-10^9 \le x \le 10^9)—— 表示从第 ⌈n2⌉+1\lceil{\frac{n}{2}}\rceil + 1 个月到第 nn 个月,每个月的收入均为 xx。

输出格式

In a single line, print the appropriate integer kk or −1-1, if it does not exist.

If there are multiple possible answers, you can print any.

在一行中输出合适的整数 kk,如果不存在则输出 −1-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=2k=2 and k=3k=3 satisfy: in the first case, Levian will report the numbers 1,11, 1, and in the second case — one number 33.

In the second example, there is no such kk.

In the third example, the only answer is k=4k=4: he will report the numbers 1,2,31,2,3.

在第一个例子中,k=2k=2 和 k=3k=3 均满足条件:在第一种情况下,Levian 将报告数字 1,11, 1;在第二种情况下,他将报告一个数字 33。

在第二个例子中,不存在满足条件的 kk。

在第三个例子中,唯一解为 k=4k=4:他将报告数字 1,2,31,2,3。

输入解题思路,AI测评打分。不知道怎么写?

首页