标签:
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 5 using namespace std; 6 7 const int maxn=100005; 8 9 int dp[2*maxn]; 10 int v[2*maxn]; 11 12 int main() 13 { 14 int n; 15 16 while(scanf("%d",&n)!=EOF) 17 { 18 int val,cost; 19 20 for(int i=1;i<=n;i++) 21 { 22 scanf("%d%d",&val,&cost); 23 v[i]=val-cost; 24 } 25 26 for(int i=n+1;i<2*n;i++) 27 v[i]=v[i-n]; 28 29 dp[0]=0; 30 31 int sum=0; 32 33 for(int i=1;i<2*n;i++) 34 { 35 sum+=v[i]; 36 if(sum<0) 37 { 38 sum=0; 39 dp[i]=0; 40 continue; 41 } 42 dp[i]=dp[i-1]+1; 43 } 44 45 int ans=0; 46 47 for(int i=1;i<2*n;i++) 48 if(dp[i]>ans) 49 ans=dp[i]; 50 51 if(ans>n) 52 ans=n; 53 54 printf("%d\n",ans); 55 } 56 57 return 0; 58 59 }
标签:
原文地址:http://www.cnblogs.com/-maybe/p/4446511.html