estie プログラミングコンテスト2025 (AtCoder Regular Contest 210)
A
Always Increasing
AtCoder
⌀ 995
原题
←B →
翻译中…

Problem Statement

翻译中…

You are given a sequence of positive integers $A=(A_1,A_2,\ldots,A_N)$ of length $N$, and you will perform $Q$ operations on it. For $1\leq q\leq Q$, the $q$-th operation is given as positive integers $i_q, x_q$ (where $1\leq i_q\leq N$), and it adds $x_q$ to $A_{i_q}$.

翻译中…

Your goal is to appropriately determine the initial state of $A$ so that the following condition holds at any point in time (that is, in the initial state and immediately after each operation).

翻译中…
  • $0<A_1 < A_2 < \cdots < A_N$ holds.
翻译中…

When achieving this goal, find the minimum possible sum of elements in the initial state of $A$.

翻译中…

Constraints

翻译中…
  • $2\leq N\leq 2\times 10^5$
  • $1\leq Q\leq 2\times 10^5$
  • $1\leq i_q\leq N$
  • $1\leq x_q\leq 10^5$
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N Q
i_1 x_1
\vdots
i_Q x_Q

翻译中…

Output

翻译中…

Output the minimum possible sum of elements in the initial state of $A$ when achieving the goal.

翻译中…

样例

Input #1
4 2
1 2
2 3
Output #1
22
Suppose the initial state of $A$ is $A=(1,4,8,9)$. Then, - $A$ immediately after the $1$-st operation: $A=(3,4,8,9)$ - $A$ immediately after the $2$-nd operation: $A=(3,7,8,9)$ and it can be verified that $A$ satisfies the condition at any point in time. In this case, the sum of elements in the initial state of $A$ is $\displaystyle \sum_{i=1}^NA_i=1+4+8+9=22$.
Input #2
4 2
2 3
1 2
Output #2
16
Input #3
100000 1
1 100000
Output #3
14999950000
题目信息
题号
arc210_a
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。