参考代码:
1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 5 const int maxn = 400000 + 5; 6 int value[maxn]; 7 int n; 8 9 int main() { 10 cin >> n; 11 for(int i = 0; i < n; i ++) cin >> value[i]; 12 for(int i = 0; i < n; i ++) value[i + n] = value[i]; 13 int ans = 0, Max = 0; 14 for(int i = 0; i < 2 * n; i ++) { 15 if(value[i]) Max ++; 16 else Max = 0; 17 ans = max(ans, Max); 18 } 19 cout << ans << endl; 20 return 0; 21 }