#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
const int maxN=1e6+5;
const ll inf=2e18;
int n;
ll a,b;
pll p[maxN+1];
set<pll> se;
int main()
{
//freopen("","r",stdin);
//freopen("","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>a>>b;
for(int i=1;i<=n;i++)
{
cin>>p[i].fi>>p[i].se;
}
ll x=inf,d=__gcd(a,b+1);
if((ld)1.0*inf/b<a/d)
{
x=inf;
}
else x=b*(a/d);
for(int i=1;i<=n;i++)
{
if(p[i].se-p[i].fi+1>=x)
{
cout<<x;
return 0;
}
ll lmod=p[i].fi%x,rmod=p[i].se%x;
if(lmod>rmod)
{
se.insert({lmod,x-1});
se.insert({0,rmod});
}
else se.insert({lmod,rmod});
}
ll ans=0,mx=-1;
for(auto i:se)
{
ans+=max(0ll,i.se-max(mx+1,i.fi)+1);
mx=max(mx,i.se);
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
1372 KB |
Output is correct |
3 |
Correct |
3 ms |
1372 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
468 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 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 |
3 ms |
1372 KB |
Output is correct |
17 |
Correct |
30 ms |
12540 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
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 |
Correct |
132 ms |
41076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
316 ms |
115764 KB |
Output is correct |
3 |
Correct |
377 ms |
115816 KB |
Output is correct |
4 |
Correct |
352 ms |
115804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
316 ms |
115764 KB |
Output is correct |
3 |
Correct |
377 ms |
115816 KB |
Output is correct |
4 |
Correct |
352 ms |
115804 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
324 ms |
115812 KB |
Output is correct |
7 |
Correct |
330 ms |
115792 KB |
Output is correct |
8 |
Correct |
338 ms |
115944 KB |
Output is correct |
9 |
Correct |
354 ms |
115796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
316 ms |
115764 KB |
Output is correct |
3 |
Correct |
377 ms |
115816 KB |
Output is correct |
4 |
Correct |
352 ms |
115804 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
27 ms |
12520 KB |
Output is correct |
7 |
Correct |
36 ms |
12624 KB |
Output is correct |
8 |
Correct |
27 ms |
12624 KB |
Output is correct |
9 |
Correct |
30 ms |
12644 KB |
Output is correct |
10 |
Correct |
28 ms |
12624 KB |
Output is correct |
11 |
Correct |
28 ms |
12516 KB |
Output is correct |
12 |
Correct |
30 ms |
12596 KB |
Output is correct |
13 |
Correct |
31 ms |
12880 KB |
Output is correct |
14 |
Correct |
30 ms |
12524 KB |
Output is correct |
15 |
Correct |
33 ms |
12628 KB |
Output is correct |
16 |
Correct |
37 ms |
12520 KB |
Output is correct |
17 |
Correct |
34 ms |
12648 KB |
Output is correct |
18 |
Correct |
331 ms |
115692 KB |
Output is correct |
19 |
Correct |
331 ms |
115812 KB |
Output is correct |
20 |
Correct |
350 ms |
115696 KB |
Output is correct |
21 |
Correct |
30 ms |
12648 KB |
Output is correct |
22 |
Correct |
29 ms |
12632 KB |
Output is correct |
23 |
Correct |
59 ms |
19280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
31 ms |
12600 KB |
Output is correct |
3 |
Correct |
31 ms |
12576 KB |
Output is correct |
4 |
Correct |
370 ms |
115860 KB |
Output is correct |
5 |
Correct |
33 ms |
12624 KB |
Output is correct |
6 |
Correct |
32 ms |
12520 KB |
Output is correct |
7 |
Correct |
32 ms |
12628 KB |
Output is correct |
8 |
Correct |
30 ms |
12628 KB |
Output is correct |
9 |
Correct |
31 ms |
12624 KB |
Output is correct |
10 |
Correct |
28 ms |
12624 KB |
Output is correct |
11 |
Correct |
30 ms |
12628 KB |
Output is correct |
12 |
Correct |
30 ms |
12624 KB |
Output is correct |
13 |
Correct |
30 ms |
12552 KB |
Output is correct |
14 |
Correct |
361 ms |
115792 KB |
Output is correct |
15 |
Correct |
27 ms |
12632 KB |
Output is correct |
16 |
Correct |
329 ms |
115832 KB |
Output is correct |
17 |
Correct |
322 ms |
115792 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
1372 KB |
Output is correct |
3 |
Correct |
3 ms |
1372 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
468 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 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 |
3 ms |
1372 KB |
Output is correct |
17 |
Correct |
30 ms |
12540 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
600 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
132 ms |
41076 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
316 ms |
115764 KB |
Output is correct |
31 |
Correct |
377 ms |
115816 KB |
Output is correct |
32 |
Correct |
352 ms |
115804 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
324 ms |
115812 KB |
Output is correct |
35 |
Correct |
330 ms |
115792 KB |
Output is correct |
36 |
Correct |
338 ms |
115944 KB |
Output is correct |
37 |
Correct |
354 ms |
115796 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
27 ms |
12520 KB |
Output is correct |
40 |
Correct |
36 ms |
12624 KB |
Output is correct |
41 |
Correct |
27 ms |
12624 KB |
Output is correct |
42 |
Correct |
30 ms |
12644 KB |
Output is correct |
43 |
Correct |
28 ms |
12624 KB |
Output is correct |
44 |
Correct |
28 ms |
12516 KB |
Output is correct |
45 |
Correct |
30 ms |
12596 KB |
Output is correct |
46 |
Correct |
31 ms |
12880 KB |
Output is correct |
47 |
Correct |
30 ms |
12524 KB |
Output is correct |
48 |
Correct |
33 ms |
12628 KB |
Output is correct |
49 |
Correct |
37 ms |
12520 KB |
Output is correct |
50 |
Correct |
34 ms |
12648 KB |
Output is correct |
51 |
Correct |
331 ms |
115692 KB |
Output is correct |
52 |
Correct |
331 ms |
115812 KB |
Output is correct |
53 |
Correct |
350 ms |
115696 KB |
Output is correct |
54 |
Correct |
30 ms |
12648 KB |
Output is correct |
55 |
Correct |
29 ms |
12632 KB |
Output is correct |
56 |
Correct |
59 ms |
19280 KB |
Output is correct |
57 |
Correct |
0 ms |
344 KB |
Output is correct |
58 |
Correct |
31 ms |
12600 KB |
Output is correct |
59 |
Correct |
31 ms |
12576 KB |
Output is correct |
60 |
Correct |
370 ms |
115860 KB |
Output is correct |
61 |
Correct |
33 ms |
12624 KB |
Output is correct |
62 |
Correct |
32 ms |
12520 KB |
Output is correct |
63 |
Correct |
32 ms |
12628 KB |
Output is correct |
64 |
Correct |
30 ms |
12628 KB |
Output is correct |
65 |
Correct |
31 ms |
12624 KB |
Output is correct |
66 |
Correct |
28 ms |
12624 KB |
Output is correct |
67 |
Correct |
30 ms |
12628 KB |
Output is correct |
68 |
Correct |
30 ms |
12624 KB |
Output is correct |
69 |
Correct |
30 ms |
12552 KB |
Output is correct |
70 |
Correct |
361 ms |
115792 KB |
Output is correct |
71 |
Correct |
27 ms |
12632 KB |
Output is correct |
72 |
Correct |
329 ms |
115832 KB |
Output is correct |
73 |
Correct |
322 ms |
115792 KB |
Output is correct |
74 |
Correct |
0 ms |
344 KB |
Output is correct |
75 |
Correct |
0 ms |
348 KB |
Output is correct |
76 |
Correct |
0 ms |
604 KB |
Output is correct |
77 |
Correct |
0 ms |
348 KB |
Output is correct |
78 |
Correct |
0 ms |
348 KB |
Output is correct |
79 |
Correct |
3 ms |
1372 KB |
Output is correct |
80 |
Correct |
361 ms |
115692 KB |
Output is correct |
81 |
Correct |
354 ms |
115960 KB |
Output is correct |
82 |
Correct |
371 ms |
115792 KB |
Output is correct |
83 |
Correct |
363 ms |
115768 KB |
Output is correct |
84 |
Correct |
368 ms |
115808 KB |
Output is correct |
85 |
Correct |
358 ms |
115848 KB |
Output is correct |
86 |
Correct |
58 ms |
19284 KB |
Output is correct |
87 |
Correct |
0 ms |
468 KB |
Output is correct |