#include<bits/stdc++.h>
#define int long long
#define MOD 1000000007
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main(){
int n,a,b;
cin>>n>>a>>b;
int x=b*(a/__gcd(a,b+1));
vector<pair<int,int>>pre;
for(int i=0;i<n;i++){
int l,r;
cin>>l>>r;
if(r-l+1>=x){
cout<<x<<endl;
return 0;
}
if(l%x>r%x){
pre.pb({0,1});
pre.pb({r%x+1,-1});
pre.pb({l%x,1});
pre.pb({x,-1});
}
else{
pre.pb({l%x,1});
pre.pb({r%x+1,-1});
}
}
sort(all(pre));
int sum=0,ans=0,last=pre[0].ff;
for(auto i:pre){
if(sum>0){
ans+=i.ff-last;
}
sum+=i.ss;
last=i.ff;
}
cout<<ans<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
8 ms |
932 KB |
Output is correct |
3 |
Correct |
13 ms |
984 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
9 ms |
868 KB |
Output is correct |
17 |
Correct |
85 ms |
7288 KB |
Output is correct |
18 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
440 KB |
Output is correct |
5 |
Correct |
551 ms |
37244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
761 ms |
37320 KB |
Output is correct |
3 |
Correct |
814 ms |
38624 KB |
Output is correct |
4 |
Correct |
781 ms |
38364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
761 ms |
37320 KB |
Output is correct |
3 |
Correct |
814 ms |
38624 KB |
Output is correct |
4 |
Correct |
781 ms |
38364 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
814 ms |
38296 KB |
Output is correct |
7 |
Correct |
797 ms |
38508 KB |
Output is correct |
8 |
Correct |
776 ms |
37296 KB |
Output is correct |
9 |
Correct |
812 ms |
37280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
761 ms |
37320 KB |
Output is correct |
3 |
Correct |
814 ms |
38624 KB |
Output is correct |
4 |
Correct |
781 ms |
38364 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
77 ms |
5020 KB |
Output is correct |
7 |
Correct |
77 ms |
6592 KB |
Output is correct |
8 |
Correct |
84 ms |
5564 KB |
Output is correct |
9 |
Correct |
88 ms |
6076 KB |
Output is correct |
10 |
Correct |
75 ms |
5040 KB |
Output is correct |
11 |
Correct |
78 ms |
4796 KB |
Output is correct |
12 |
Correct |
75 ms |
5028 KB |
Output is correct |
13 |
Correct |
80 ms |
5824 KB |
Output is correct |
14 |
Correct |
75 ms |
5820 KB |
Output is correct |
15 |
Correct |
84 ms |
4904 KB |
Output is correct |
16 |
Correct |
80 ms |
5432 KB |
Output is correct |
17 |
Correct |
76 ms |
5568 KB |
Output is correct |
18 |
Correct |
788 ms |
37632 KB |
Output is correct |
19 |
Correct |
751 ms |
37244 KB |
Output is correct |
20 |
Correct |
808 ms |
38560 KB |
Output is correct |
21 |
Correct |
84 ms |
6848 KB |
Output is correct |
22 |
Correct |
74 ms |
4804 KB |
Output is correct |
23 |
Correct |
248 ms |
19632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
83 ms |
4740 KB |
Output is correct |
3 |
Correct |
81 ms |
5060 KB |
Output is correct |
4 |
Correct |
844 ms |
37044 KB |
Output is correct |
5 |
Correct |
81 ms |
5052 KB |
Output is correct |
6 |
Correct |
79 ms |
5824 KB |
Output is correct |
7 |
Correct |
84 ms |
5312 KB |
Output is correct |
8 |
Correct |
82 ms |
4804 KB |
Output is correct |
9 |
Correct |
80 ms |
5820 KB |
Output is correct |
10 |
Correct |
83 ms |
6596 KB |
Output is correct |
11 |
Correct |
88 ms |
6332 KB |
Output is correct |
12 |
Correct |
76 ms |
6336 KB |
Output is correct |
13 |
Correct |
80 ms |
5312 KB |
Output is correct |
14 |
Correct |
864 ms |
43656 KB |
Output is correct |
15 |
Correct |
85 ms |
5828 KB |
Output is correct |
16 |
Correct |
768 ms |
43168 KB |
Output is correct |
17 |
Correct |
808 ms |
43192 KB |
Output is correct |
18 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
8 ms |
932 KB |
Output is correct |
3 |
Correct |
13 ms |
984 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
9 ms |
868 KB |
Output is correct |
17 |
Correct |
85 ms |
7288 KB |
Output is correct |
18 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |