#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(z<=w){
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++){
~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
8 ms |
732 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
420 KB |
Output is correct |
2 |
Incorrect |
2 ms |
292 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
617 ms |
16912 KB |
Output is correct |
3 |
Correct |
610 ms |
16932 KB |
Output is correct |
4 |
Correct |
612 ms |
17364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
617 ms |
16912 KB |
Output is correct |
3 |
Correct |
610 ms |
16932 KB |
Output is correct |
4 |
Correct |
612 ms |
17364 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Incorrect |
610 ms |
17452 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
617 ms |
16912 KB |
Output is correct |
3 |
Correct |
610 ms |
16932 KB |
Output is correct |
4 |
Correct |
612 ms |
17364 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Incorrect |
63 ms |
4972 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
8 ms |
732 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |