【HDOJ】1422 重温世界杯
简单题。
1 #include <stdio.h> 2 3 #define MAXN 100005 4 5 int wi[MAXN], li[MAXN]; 6 int diff[MAXN<<1]; 7 8 int main() { 9 int n, total, max; 10 int i, tmp; 11 12 while (scanf("%d", &n) != EOF) { 13 for (i=0; i<n; ++i) { 14 scanf("%d %d", &wi[i], &li[i]); 15 diff[i] = diff[i+n] = wi[i]-li[i]; 16 } 17 total = max = tmp = 0; 18 for (i=0; i<n+n; ++i) { 19 if (diff[i]>=0 || total+diff[i]>=0) { 20 total += diff[i]; 21 ++tmp; 22 } else { 23 if (tmp > max) 24 max = tmp; 25 tmp = 0; 26 total = 0; 27 } 28 } 29 if (tmp && tmp>max) 30 max = tmp; 31 if (max > n) 32 max = n; 33 printf("%d\n", max); 34 } 35 36 return 0; 37 }