#P2629. 好消息,坏消息

    ID: 1645 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>线性结构单调队列前缀和队列

好消息,坏消息

Description

Uim works as a secretary at a company. There are nn messages to inform the boss. Each message has a "goodness" value, which affects the boss’s mood. After a message is delivered, the boss’s mood becomes his previous mood plus this message’s goodness. Initially, the boss’s mood is 00. Once the boss’s mood falls below 00, he will fly into a rage and fire Uim.

To avoid being fired, Uim already knows the goodness values of these messages (which are arranged in chronological order) and wants to know how to prevent the boss from getting angry.

Uim can use a technique called "daoxu" ("倒叙"). For example, given nn messages, Uim can choose any integer kk (1kn1 \leq k \leq n), first report events kk to nn, and then report events 11 to k1k-1. In particular, when k=1k=1, the messages are reported in the original order.

He wants to know how many such values of kk can keep the boss from getting angry.

Input Format

The first line contains an integer nn (1n1061 \le n \le 10^6), the number of messages.

The second line contains nn integers. In chronological order, the ii-th message has goodness AiA_i (103Ai103-10^3 \le A_i \le 10^3).

Output Format

One line with a single integer, the number of feasible choices of kk.

4
-3 5 1 2

2

Hint

Sample Explanation:

Feasible reporting orders (by indices) are 23412\rightarrow3\rightarrow4\rightarrow1 or 34123\rightarrow4\rightarrow1\rightarrow2 (corresponding to k=2k=2 and k=3k=3, respectively).

Feasible reporting orders (by goodness values) are 512(3)5\rightarrow1\rightarrow2\rightarrow(-3) or 12(3)51\rightarrow2\rightarrow(-3)\rightarrow5.

Constraints:

For 25%25\% of the testdata, n103n \le 10^3. For 75%75\% of the testdata, n104n \le 10^4. For 100%100\% of the testdata, 1n1061 \le n \le 10^6.

Translated by ChatGPT 5