Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5099 Accepted Submission(s): 1748
3 3 2 3 4 2 2 3 3 2 3 4 2 3
3 2
#include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #include<queue> #include<stack> #include<algorithm> #define MAX 200000+10 using namespace std; int left[MAX]; int max(int x,int y) { return x>y?x:y; } int main() { int n,i,j; int sum;//记录当前拥有钱 int ans;//记录最多参观城市数目 int tmp;//记录当前可连续参观城市数目 int have,cost;//每个城市所拥有钱 和 所花费钱 while(scanf("%d",&n)!=EOF) { for(i=1;i<=n;i++) { scanf("%d%d",&have,&cost); left[i]=left[n+i]=have-cost; } sum=ans=tmp=0; for(i=1;i<=2*n;i++) { sum+=left[i]; if(sum>=0) tmp++; else sum=tmp=0; ans=max(ans,tmp);//每次更新 } if(ans>n)//若可参观城市超过总数 ans=n; printf("%d\n",ans); } return 0; }