#include <bits/stdc++.h>
using namespace std;
long long n,a,b,ans,i,t,k,pozst,lg,schema,ok,st,dr;
struct ceva
{
long long l,r;
}v[1000010];
bool cmp(ceva a,ceva b)
{
return a.r<b.r || (a.r==b.r && a.l<b.l);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>a>>b;
//for(t=1;t<=100;t++)
// cout<<(t%a+t/b%a)%a<<" "<<t%b<<" TIMPUL: "<<t<<'\n';
for(i=1;i<=n;i++)
{
cin>>v[i].l>>v[i].r;
k=a*b;
pozst=v[i].l%k;
lg=v[i].r-v[i].l+1;
if(lg>=k)
{
ok=1;
ans=k;
}
if(pozst==0)
{
v[n+(++schema)]={k,k};
pozst=1;
v[i].l=1;
v[i].r=v[i].l+lg-2;
lg--;
}
if(pozst+lg-1>k)
{
v[n+(++schema)]={pozst,k};
v[i]={1,k-pozst-lg-1};
}
else
v[i]={pozst,pozst+lg-1};
}
if(ok==1)
{
cout<<k;
return 0;
}
n=n+schema;
sort(v+1,v+n+1,cmp);
//for(i=1;i<=n;i++)
// cout<<v[i].l<<" "<<v[i].r<<'\n';
st=0;
dr=0;
for(i=1;i<=n;i++)
{
st=max(st,v[i].l);
st=max(st,v[i-1].r+1);
if(dr==v[i].r)
continue;
dr=v[i].r;
st=max(st,v[i].l);
st=max(st,v[i-1].r+1);
ans=ans+dr-st+1;
}
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
3 ms |
604 KB |
Output isn't correct |
3 |
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 |
0 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 |
500 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
346 ms |
16344 KB |
Output is correct |
3 |
Incorrect |
399 ms |
53288 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
346 ms |
16344 KB |
Output is correct |
3 |
Incorrect |
399 ms |
53288 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
346 ms |
16344 KB |
Output is correct |
3 |
Incorrect |
399 ms |
53288 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
37 ms |
2652 KB |
Output is correct |
3 |
Correct |
38 ms |
6228 KB |
Output is correct |
4 |
Correct |
436 ms |
53292 KB |
Output is correct |
5 |
Correct |
42 ms |
6224 KB |
Output is correct |
6 |
Correct |
45 ms |
6372 KB |
Output is correct |
7 |
Correct |
38 ms |
6224 KB |
Output is correct |
8 |
Correct |
40 ms |
6396 KB |
Output is correct |
9 |
Correct |
41 ms |
6204 KB |
Output is correct |
10 |
Correct |
37 ms |
6396 KB |
Output is correct |
11 |
Correct |
47 ms |
6228 KB |
Output is correct |
12 |
Incorrect |
32 ms |
6292 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
3 ms |
604 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |