题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1422
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=500005;
LL a[N];
int main()
{
LL n,x,y;
cin.sync_with_stdio(false);
while(cin>>n){
for(LL i=1;i<=n;i++){
cin>>x>>y;
a[i]=x-y;
a[i+n]=x-y;
}
LL sum=0;
LL cnt=0;
LL ans=0;
for(LL i=1;i<=2*n;i++){
sum+=a[i];
cnt++;
if(sum<0){
cnt=0;
sum=0;
}
ans=max(ans,cnt);
if(ans>=n) break;
}
cout<<ans<<endl;
}
return 0;
}