This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
inline namespace
{
} // namespace
void solve()
{
int n;
long a, b;
cin >> n >> a >> b;
vector<array<long, 2>> v(n);
for (auto &[x, y] : v)
cin >> x >> y, ++y;
long c = a * b / gcd(a, b + 1);
vector<array<long, 2>> u;
for (auto [x, y] : v)
{
if (y - x >= c)
u.push_back({0, c});
else
{
x %= c, y %= c;
if (x < y)
u.push_back({x, y});
else
u.push_back({x, c}), u.push_back({0, y});
}
}
sort(u.begin(), u.end());
long cnt = 0;
long d = 0;
for (auto [x, y] : u)
{
if (y > d)
{
cnt += y - max(x, d);
d = y;
}
}
cout << cnt << '\n';
}
int main()
{
ios_base::sync_with_stdio(false), cin.tie(NULL);
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |