No.1557 Binary Variable
Problem Statement
A variable that takes an integer value of either $0$ or $1$ is called a binary variable.
You are given positive integers $N,M$ and $M$ pairs of positive integers. The $i$-th pair is $(L_i,R_i)$.
When $N$ binary variables $B_1,B_2,\dots ,B_N$ satisfy $\displaystyle\sum_{i=1}^{M} \prod_{j=L_i}^{R_i} B_j = 0$, find the maximum possible value of $\displaystyle S=\sum_{k=1}^{N} B_k$.
Constraints
Input
$N\ M$ $L_1\ R_1$ $\ \vdots \quad \vdots$ $L_M\ R_M$
Output
Output the maximum possible value of $S$.
Print a newline at the end.
Sample
Sample 1
Input
5 2 1 3 3 5
Output
4
Setting $(B_1,B_2,B_3,B_4,B_5)=(1,1,0,1,1)$ satisfies the condition.
In this case $S=4$, and it cannot be made larger than this, so output $4$.
Sample 2
Input
3 4 1 1 1 2 2 3 3 3
Output
1
It is possible that $L_i=R_i$.
Sample 3
Input
11 7 1 4 3 7 2 5 5 9 7 8 3 3 10 11
Output
8
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
noya2
nok0
magsta