#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(v) (v).begin(),(v).end()
const int MOD = 1000000007;
const int N = 1000005;
const double PI =4*atan(1);
const double eps = 1e-7;
ll n;
ll a,b;
set<pair<ll,ll> > ss;
vector<pair<ll,ll> > v;
int main(){
ios::sync_with_stdio(0);
//freopen("easy.txt","r",stdin);
cin >> n >> a >> b;
if(a%2==0)a/=2;
for(int i=0;i<n;i++){
ll x,y;
cin >> x >> y;
if(y-x+1>=a){
cout << a;
return 0;
}
ll z=x%a;
ll w=y%a;
if(x>=z){
v.pb(mp(z,w));
}else{
v.pb(mp(z,a-1));
v.pb(mp(0,w));
}
}
sort(all(v));
ll ans=v[0].s-v[0].f+1;
ll l=v[0].s;
for(int i=1 ;i<v.size();i++){
if(v[i].f>l){
ans+=v[i].s-v[i].f+1;
l=v[i].s;
}else{
ans+=v[i].s-l;
l=v[i].s;
}
}
cout << ans;
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:51:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=1 ;i<v.size();i++){
~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
8 ms |
760 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
627 ms |
16892 KB |
Output is correct |
3 |
Incorrect |
629 ms |
16856 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
627 ms |
16892 KB |
Output is correct |
3 |
Incorrect |
629 ms |
16856 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
627 ms |
16892 KB |
Output is correct |
3 |
Incorrect |
629 ms |
16856 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
8 ms |
760 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |