#include<bits/stdc++.h>
#include <deque>
#include <cmath>
using namespace std;
#define ll long long
/*freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);*/
long long x , y , z , i , j , n , m , k , s1 , s2 , s3 , s4 , s5 , s6 , mod , l , r , t , maxx , minn , sx , so , sum , mid , ans , puk , par , chi , sz , choc1 , choc2 , len , depth ;
pair < long long , long long > aa [ 2000045 ] ;
int main() {
cin >> n >> x >> y ;
z = x / ( __gcd ( x , y + 1 ) ) ;
if ( z > 1000000000000000000 / y ) {
k = 1000000000000000001 ;
}
else {
k = z * y ;
}
x = 0 ;
for ( i = 1 ; i <= n ; i ++ ) {
cin >> l >> y ;
if ( r - l + 1 >= k ) {
cout << k ;
exit (0) ;
}
l %= k ;
r %= k ;
if ( l <= r ) {
x ++ ;
aa [ x ] . first = l ;
aa [ x ] . second = r ;
}
else {
x ++ ;
aa [ x ] . first = l ;
aa [ x ] . second = k - 1 ;
x ++ ;
aa [ x ] . first = 0 ;
aa [ x ] . second = r ;
}
}
sort ( aa + 1 , aa + x + 1 ) ;
r = -1 ;
ans = 0 ;
for ( i = 1 ; i <= x ; i ++ ) {
r = max ( r , aa [ i ] . first - 1 ) ;
ans += max ( aa [ i ] . second - r , so ) ;
r = max ( aa [ i ] . second , r ) ;
}
cout << ans ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Incorrect |
21 ms |
640 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2144 ms |
32148 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2144 ms |
32148 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2144 ms |
32148 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Incorrect |
225 ms |
3384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Incorrect |
21 ms |
640 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |