Universal Cup Judging System

Universal Cup

Süre Sınırı: 7.0 s Bellek Sınırı: 1024 MB Toplam puan: 100 Hack'lenebilir ✓
İstatistikler

Descrizione

Helloooo! Can you hear me?

Ti viene data una sequenza $A = (A_1, A_2, \dots, A_N)$ di lunghezza $N$ composta da interi maggiori o uguali a $-1$. Utilizzando questa sequenza e un parametro $c$, esegui le seguenti operazioni:

  • Inizialmente, imposta la variabile $x := 0$.
  • Per $i = 1, 2, \dots, N$, ripeti la seguente operazione:
    • Se $A_i = -1$, aggiorna $x$ a $x := \max(0, x - c)$.
    • Altrimenti, aggiorna $x$ a $x := x + A_i$.

Rispondi a $Q$ domande della seguente forma:

  • Quando il parametro è $c = C_i$, trova il valore massimo raggiunto da $x$ durante l'intera sequenza di operazioni.

Input

La prima riga contiene due interi $N$ e $Q$ ($1 \le N, Q \le 3 \times 10^5$). La seconda riga contiene $N$ interi $A_i$ ($-1 \le A_i \le 10^6$). Ciascuna delle successive $Q$ righe contiene un intero $C_i$, che rappresenta il valore del parametro per la $i$-esima domanda ($0 \le C_i \le 10^6$).

Output

Stampa $Q$ righe. Sulla $i$-esima riga, stampa la risposta alla $i$-esima domanda.

Esempi

Input 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

Output 1

1700
1550
1400
950
570
500
500
850
500
500
1850

Note

Spieghiamo la prima domanda del primo esempio di input:

  • In questa domanda, il parametro è $c = 30$.
  • Inizialmente, $x = 0$.
  • Poiché $A_1 = 50$, $x$ viene aggiornato a $x = 0 + 50 = 50$.
  • Poiché $A_2 = 100$, $x$ viene aggiornato a $x = 50 + 100 = 150$.
  • ...
  • Poiché $A_6 = 200$, $x$ viene aggiornato a $x = 300 + 200 = 500$.
  • Poiché $A_7 = -1$, $x$ viene aggiornato a $x = \max(0, 500 - 30) = 470$.
  • ...
  • Poiché $A_{19} = -1$, $x$ viene aggiornato a $x = \max(0, 1530 - 30) = 1500$.
  • Poiché $A_{20} = 200$, $x$ viene aggiornato a $x = 1500 + 200 = 1700$.

Includendo le parti omesse, il valore massimo raggiunto da $x$ durante l'intera sequenza di operazioni è $1700$.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1534EditorialOpen题解jianglyView

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.