显示代码纯文本
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int min(int a, int b)
{
if(a > b)
{
return b;
}
return a;
}
int max(int a, int b)
{
if(a > b)
{
return a;
}
return b;
}
int main()
{
int a, b, l, r, c, pl, pr, cl, cr;
freopen("MrBA1.in", "r", stdin);
freopen("MrBA1.out", "w", stdout);
scanf(" %d %d %d %d ", &a, &b, &l, &r);
c = a + b;
cl = --l / c;
pl = l % c;
cr = --r / c;
pr = r % c;
if(cl == cr)
{
printf("%d\n", min(r - l + 1, max(a - pl, 1)));
}
else if(a <= b)
{
if(cl < cr - 1)
{
printf("%d\n", a+1);
}
else
{
int x = max(1, a - pl);
int y = min(a, pr + 1);
printf("%d\n", min(a, x + y) + (y == a));
}
}
else
{
int d = a - b;
if(cl == cr - 1)
{
printf("%d\n", max(1, min(d, a - pl))+min(a, pr + 1));
}
else if(cl == cr - 2)
{
printf("%d\n", a + max(1, d + min(0, pr - a + 1 + max(0, a - pl))));
}
else
{
printf("%d\n", a + d);
}
}
fclose(stdin);
fclose(stdout);
return 0;
}