标签:
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std; // hdu 1422 // problems //
typedef long long int LL;
const int M = 1000009,INF = 0x3fffffff;
int n, a[M * 2], dp[M], key, ans;
int main(void) {
while(~scanf("%d", &n)) {
memset(dp, 0, sizeof(dp));
ans = key = a[0] = 0;
dp[0] = 1;
for(int i = 1; i <= n; i++) {
int x, y;
scanf("%d%d", &x, &y);
a[i] = a[i + n] = x - y;
}
for(int i = 1; i <= n; i++) {
if(dp[i - 1] > 0) {
key -= a[i - 1];
dp[i] = dp[i - 1] - 1;
}
if(key < 0) {
for(int j = i + dp[i] - 1; ; j--) {
key -= a[j];
dp[i]--;
if(key >= 0) break;
}
} else {
for(int j = i + dp[i]; j < i + n; j++) {
if(key + a[j] < 0) break;
key += a[j];
dp[i]++;
}
}
if(dp[i] > ans) ans = dp[i];
if(ans == n) break;
}
printf("%d\n", ans);
}
return 0;
}
#include <stdio.h>
int main()
{
int i,n,a,b,sum,cnt,max,ar[100005];
while (scanf("%d",&n)!=EOF)
{
for (i=0;i<n;i++)
{
scanf("%d%d",&a,&b);
ar[i]=a-b;
}
sum=cnt=0;
max=-1;
for (i=0;i<2*n-1;i++)
{
sum+=ar[i%n];
if(sum>=0)
{
cnt++;
if(max<cnt)max=cnt;
if(cnt==n)break;
}
else sum=cnt=0;
}
printf("%d\n",max);
}
return 0;
}
标签:
原文地址:http://blog.csdn.net/jibancanyang/article/details/45626269