#P6879. Collecting Black and White Bear Statues
Collecting Black and White Bear Statues
Collecting Black and White Bear Statues
JOI is at a starting point on a circle with circumference \(L\). There are \(N\) statues of black and white bears, numbered from 1 to \(N\). The \(i\)th statue is located at a distance of \(X_i\) meters measured clockwise from the starting point. Each statue will explode with a sound \(\text{唔噗噗噗}\) if it is not collected within \(T_i\) seconds of the start. JOI can travel at a rate of 1 meter per second and may choose to move either clockwise or anticlockwise along the circle.
Your task is to determine the maximum number of statues that JOI can collect by planning his route so that he reaches each statue before its deadline.
inputFormat
The input begins with a line containing two integers \(L\) and \(N\) separated by a space.
In the following \(N\) lines, each line contains two integers \(X_i\) and \(T_i\), representing the clockwise distance (in meters) of the \(i\)th statue from the starting point and the deadline (in seconds) by which the statue must be collected, respectively.
outputFormat
Output a single integer, which is the maximum number of statues JOI can collect.
sample
100 3
10 15
80 25
20 202