#include <stdio.h>
#include <string.h>
#include <queue>
using namespace std;
const int maxn = 100005;
int n;
int cost[maxn];
int main()
{
//freopen( "data.in","r",stdin );
while( scanf("%d",&n) != EOF )
{
int flag = 0,w,l;
for( int i = 1; i <= n; i ++ )
{
scanf("%d%d",&w,&l);
cost[i] = w - l;
if( cost[i] >= 0 )
{
flag = 1;
}
}
if( !flag )
{
printf("0\n");
}
else
{
int beg,sum,max,cnt;
max = sum = beg = cnt = 0;
int i;
for( i = 1; i <= n; i ++ )
{
if( sum < 0 )
{
sum = 0;
cnt = 0;
beg = i;
}
sum += cost[i];
cnt ++;
if( sum >= 0 )
max = max > cnt?max:cnt;
}
if( sum >= 0 )
{
for( i = 1; i < beg && sum >= 0; i ++ )
{
sum += cost[i];
cnt ++;
if( sum >= 0 )
max = max > cnt?max:cnt;
}
}
printf("%d\n",max);
}
}
return 0;
}
hdu-1422 最长子序列和
最新推荐文章于 2018-08-07 07:02:21 发布