#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(),x.end()
const int INF=9e18;
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;cin>>t;
int a,b;cin>>a>>b;
int m=0;
if(INF/a<b){
m=INF;
}
else{
m=a*b;
}
vector<pair<int,int>> v;
for(int i=0;i<t;i++){
int l,r;cin>>l>>r;
if(r-l+1>=m){
cout<<m<<endl;
return 0;
}
if(r%m<l%m){
v.push_back({l%m,m-1});
v.push_back({0,r%m});
}
else{
v.push_back({l%m,r%m});
}
}
sort(all(v));
int ans=0;
int l=0;
for(pair<int,int> p:v){
p.first=max(p.first,l);
if(p.second<p.first){
continue;
}
ans+=(p.second-p.first+1);
l=p.second+1;
}
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
628 KB |
Output is correct |
3 |
Correct |
6 ms |
700 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
292 ms |
16832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
385 ms |
16892 KB |
Output is correct |
3 |
Incorrect |
401 ms |
16820 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
385 ms |
16892 KB |
Output is correct |
3 |
Incorrect |
401 ms |
16820 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
385 ms |
16892 KB |
Output is correct |
3 |
Incorrect |
401 ms |
16820 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
44 ms |
2436 KB |
Output is correct |
3 |
Correct |
46 ms |
2476 KB |
Output is correct |
4 |
Correct |
492 ms |
16820 KB |
Output is correct |
5 |
Correct |
40 ms |
2512 KB |
Output is correct |
6 |
Correct |
41 ms |
2480 KB |
Output is correct |
7 |
Correct |
44 ms |
2512 KB |
Output is correct |
8 |
Correct |
43 ms |
2416 KB |
Output is correct |
9 |
Correct |
47 ms |
2592 KB |
Output is correct |
10 |
Correct |
45 ms |
2512 KB |
Output is correct |
11 |
Correct |
41 ms |
2460 KB |
Output is correct |
12 |
Correct |
36 ms |
2496 KB |
Output is correct |
13 |
Correct |
42 ms |
2504 KB |
Output is correct |
14 |
Correct |
425 ms |
16776 KB |
Output is correct |
15 |
Incorrect |
54 ms |
2504 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
628 KB |
Output is correct |
3 |
Correct |
6 ms |
700 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |