根据题意,买的策略是,先买若干箱,剩下的零头直接买一箱
首先想一种极端情况,就是这个一箱个数特别大,那么所有人都不够,最小也得买一箱。
但是根据题意,是需要买一箱,但是那个极端情况告诉我们箱中物品个数尽量大一些
给定区间$l-r$
我们分情况讨论$a$的取值
1. $a<l$
2. $l\le a \le r$
3. $r<a$
如果$l\le a \le r$,那么存在一个人正好买一箱,第二种情况排除
如果箱中物品个数大于$r$,那么所有人都不够一箱,第三种情况排除
因为要是$a$尽可能的大,所以最大的就是$l-1$。
比较区间长度和l的值即可
C++ 代码
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
int T;
cin>>T;
while (T--)
{
int l,r;
cin>>l>>r;
int re = r-l;
//
if(re<l) puts("YES");
else puts("NO");
}
}