Universal Cup Judging System

Universal Cup

Límite de tiempo: 7.0 s Límite de memoria: 1024 MB Puntuación total: 100 Hackeable ✓
Estadísticas

給定一個長度為 $N$ 的數列 $A = (A_1, A_2, \dots, A_N)$,其中包含大於或等於 $-1$ 的整數。使用此數列與參數 $c$,執行以下操作:

  • 初始時,設定變數 $x := 0$。
  • 對於 $i = 1, 2, \dots, N$,重複執行以下操作:
    • 若 $A_i = -1$,將 $x$ 更新為 $x := \max(0, x - c)$。
    • 否則,將 $x$ 更新為 $x := x + A_i$。

回答 $Q$ 個以下形式的問題:

  • 當參數 $c = C_i$ 時,求出在整個操作序列中 $x$ 所能達到的最大值。

輸入格式

第一行包含 $N$ 與 $Q$($1 \le N, Q \le 3 \times 10^5$)。 第二行包含 $N$ 個整數 $A_i$($-1 \le A_i \le 10^6$)。 接下來的 $Q$ 行,每行包含一個 $C_i$ 值,代表第 $i$ 個問題的參數($0 \le C_i \le 10^6$)。

輸出格式

輸出 $Q$ 行。 在第 $i$ 行輸出第 $i$ 個問題的答案。

範例

輸入格式 1

20 11
50 100 50 100 0 200 -1 50 100 -1 200
-1 200 0 200 -1 200 200 -1 200
30
60
90
180
270
360
540
200
400
600
0

輸出格式 1

1700
1550
1400
950
570
500
500
850
500
500
1850

說明

我們解釋第一個範例輸入中的第一個問題:

  • 在此問題中,參數為 $c = 30$。
  • 初始時,變數 $x = 0$。
  • 因為 $A_1 = 50$,$x$ 更新為 $x = 0 + 50 = 50$。
  • 因為 $A_2 = 100$,$x$ 更新為 $x = 50 + 100 = 150$。
  • ...
  • 因為 $A_6 = 200$,$x$ 更新為 $x = 300 + 200 = 500$。
  • 因為 $A_7 = -1$,$x$ 更新為 $x = \max(0, 500 - 30) = 470$。
  • ...
  • 因為 $A_{19} = -1$,$x$ 更新為 $x = \max(0, 1530 - 30) = 1500$。
  • 因為 $A_{20} = 200$,$x$ 更新為 $x = 1500 + 200 = 1700$。

包含省略的部分,在整個操作序列中 $x$ 所能達到的最大值為 $1700$。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1534EditorialOpen题解jiangly2026-04-15 16:06:17View

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.