#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,a,b;
vector<pair<int,int>> eves;
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>a>>b;
for(int i=1;i<=n;i++)
{
int l,r;
cin>>l>>r;
if(r - l + 1 >= a * b)
{
cout<<a * b<<'\n';
return 0;
}
l %= a * b;
r %= a * b;
if(l <= r)
{
eves.push_back({l,1});
eves.push_back({r+1,-1});
}
else
{
eves.push_back({0,1});
eves.push_back({r+1,-1});
eves.push_back({l,1});
eves.push_back({a*b,-1});
}
}
sort(eves.begin(),eves.end());
int nr = 0;
int rez = 0;
int last = 0;
for(auto it : eves)
{
if(nr==0 && it.second==1)
{
last = it.first;
}
nr += it.second;
if(nr==0 && it.second==-1)
{
rez += it.first - last;
}
}
cout<<rez<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
856 KB |
Output is correct |
3 |
Correct |
6 ms |
1240 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
0 ms |
324 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
331 ms |
33180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
474 ms |
33236 KB |
Output is correct |
3 |
Incorrect |
513 ms |
68888 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
474 ms |
33236 KB |
Output is correct |
3 |
Incorrect |
513 ms |
68888 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
474 ms |
33236 KB |
Output is correct |
3 |
Incorrect |
513 ms |
68888 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
53 ms |
4444 KB |
Output is correct |
3 |
Correct |
53 ms |
7236 KB |
Output is correct |
4 |
Correct |
627 ms |
68768 KB |
Output is correct |
5 |
Correct |
54 ms |
7308 KB |
Output is correct |
6 |
Correct |
51 ms |
7220 KB |
Output is correct |
7 |
Correct |
60 ms |
7260 KB |
Output is correct |
8 |
Correct |
78 ms |
7300 KB |
Output is correct |
9 |
Correct |
60 ms |
7196 KB |
Output is correct |
10 |
Correct |
54 ms |
7280 KB |
Output is correct |
11 |
Correct |
53 ms |
7304 KB |
Output is correct |
12 |
Correct |
47 ms |
7228 KB |
Output is correct |
13 |
Correct |
60 ms |
7260 KB |
Output is correct |
14 |
Correct |
590 ms |
68828 KB |
Output is correct |
15 |
Incorrect |
57 ms |
7372 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
856 KB |
Output is correct |
3 |
Correct |
6 ms |
1240 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |