Score : $500$ points
Takahashi has a secret integer sequence $a$. You know that the length of $a$ is $N$.
You want to guess the contents of $a$. He has promised to give you the following $Q$ additional pieces of information.
Is it possible to determine the sum of all elements in $a$, $a_1+a_2+\cdots+a_N$, if the $Q$ pieces of promised information are given?
Input is given from Standard Input in the following format:
$N$ $Q$ $l_1$ $r_1$ $l_2$ $r_2$ $\hspace{0.4cm}\vdots$ $l_Q$ $r_Q$
If it is possible to determine the sum of all elements in $a$, print Yes
; otherwise, print No
.
3 3 1 2 2 3 2 2
Yes
From the first and second information, we can find the value $a_1+a_2+a_2+a_3$. By subtracting the value of $a_2$ from it, we can determine the value $a_1+a_2+a_3$.
4 3 1 3 1 2 2 3
No
We can determine the sum of the first $3$ elements of $a$, but not the sum of all elements.
4 4 1 1 2 2 3 3 1 4
Yes
The fourth information directly gives us the sum of all elements.