Public Judge

pjudge

حد الوقت: 2 s حد الذاكرة: 512 MB مجموع النقاط: 100 قابلة للهجوم ✓

#21671. 【NOIP Round #1】Candies in the Box

الإحصائيات

There are $n$ boxes on a table, with the $i$-th box from the left initially containing $a_i$ candies.

Little P performs $m$ operations. Each operation has parameters $l$ and $r$. For each operation, Little P can choose to perform one of the following:

  1. Add one candy to each box from the $l$-th to the $r$-th box.
  2. Arbitrarily rearrange the candies in the boxes from the $l$-th to the $r$-th box.

Little P wants to know, after all operations are completed, what is the maximum number of candies that can be contained in each box.

Input

The first line contains two integers $n$ and $m$, representing the number of boxes and the number of operations.

The second line contains $n$ integers, where the $i$-th integer $a_i$ represents the initial number of candies in the $i$-th box.

The next $m$ lines each contain two integers $l$ and $r$, describing an operation.

Output

Output a single line containing $n$ integers, where the $i$-th integer represents the maximum number of candies that can be in the $i$-th box.

Examples

Input 1

4 5
1 2 2 3
2 2
2 2
1 3
1 3
3 4

Output 1

5 6 6 5

Note 1

An explanation of a method to make the $4$-th box contain $5$ candies:

$(1,2,2,3)\rightarrow(1,3,2,3)\rightarrow(1,4,2,3)\rightarrow(1,2,4,3)\rightarrow(2,3,5,3)\rightarrow(2,3,3,5)$

Input 2

See attachment.

Constraints

For $30\%$ of the data, $n\leq 5, m\leq 3$.

For $60\%$ of the data, $n, m\leq 5000$.

For $100\%$ of the data, $1\leq n, m\leq 5\times 10^5, 1\leq a_i\leq 10^9, 1\leq l\leq r\leq n$.

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.