ALGO ARTIS プログラミングコンテスト2023 秋 (AtCoder Regular Contest 168)
D
Maximize Update
AtCoder
⌀ 2440
原题
← CE →
翻译中…

Problem Statement

翻译中…

There are $N$ squares arranged in a row, numbered $1$ to $N$ from left to right. Initially, all squares are white.

翻译中…

You can perform the following $M$ types of operations any number of times in any order:

翻译中…
  • Type-$i$ operation: Paint square $L_i$ through square $R_i$ in black.
翻译中…

Find the maximum number of times the operations can change the state of the squares. If an operation changes the color of at least one square, that operation is considered to change the state of the squares.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 500$
  • $1 \leq M \leq N(N+1)/2$
  • $1 \leq L_i \leq R_i \leq N$
  • $(L_i,R_i) \neq (L_j,R_j)$ for all $i \neq j$
  • All input values are integers.
翻译中…

Input

翻译中…

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

翻译中…

N M
L_1 R_1
L_2 R_2
\vdots
L_M R_M

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
3 3
1 3
1 1
3 3
Output #1
3
If you perform the operations as follows, they will change the state of the squares three times. - Perform type-$2$ operation. Square $1$ is newly painted black. - Perform type-$3$ operation. Square $3$ is newly painted black. - Perform type-$1$ operation. Square $2$ is newly painted black.
Input #2
4 3
1 2
3 4
1 4
Output #2
2
Input #3
5 5
4 5
1 1
2 4
1 2
2 5
Output #3
4
Input #4
20 15
2 4
16 19
7 13
1 15
3 18
10 11
1 10
1 7
14 16
1 16
2 17
1 17
12 14
3 17
4 10
Output #4
11
题目信息
题号
arc168_d
时间限制
2 s
内存限制
1024 MB

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