Codeforces 1141B. Maximal Continuous Rest





Problem Link

A solution in c++

#include<bits/stdc++.h>

using namespace std;

/// Typedef
typedef long long ll;

#define sc1(a) scanf("%lld",&a)
#define sc2(a, b) scanf("%lld %lld",&a,&b)

#define pf1(a) printf("%lld\n", a)
#define pf2(a, b) printf("%lld %lld\n",a,b)

#define mx 1000000
#define PI acos(-1.0)
#define Accepted 0


int main() {

    int num;
    cin >> num;

    vector < int > ar(num);

    for (int i = 0; i < num; i++)
        cin >> ar[i];

    int res = 0, len = 0;

    for (int i = 0; i < num*2; i++) {
        if (ar[i%num] != 0) {
            len++;

            res = max(res, len);
        } else {
            len = 0;
        }
    }

    cout << res << endl;

    return Accepted;
}







No comments

Theme images by Jason Morrow. Powered by Blogger.