2021-08-20 AcWing 3810. 最长连续休息时间

输入样例:

4
5
1 0 1 0 1
6
0 1 0 1 1 0
7
1 0 1 1 1 0 1
3
0 0 0

输出样例:

2
2
3
0

 

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int N = 400010;
vector<int> a(N);
int main()
{
    int t,n;
    cin >> t;
    while(t--)
    {
        cin >> n;
        int cnt=0;
        int maxx=-1;
        for (int i = 0; i < n; i ++ )
        {
            scanf("%d", &a[i]);
            a[n+i]=a[i];
            
        }
        for (int i = 0; i < 2*n; i ++ ){
            if(a[i]){
                cnt++;
            }else{
                cnt=0;
            }
            maxx = max(cnt,maxx);
        }
        cout <<maxx << endl;
    }
    return 0;
}

posted @ 2021-08-20 23:06  泥烟  阅读(21)  评论(0编辑  收藏  举报