fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long int
  3. #define pb push_back
  4. #define mp make_pair
  5. #define ff first
  6. #define ss second
  7. #define vi vector<int>
  8. #define br cout <<"\n";
  9. #define all(x) (x).begin(),(x).end()
  10. #define tr(c,i) for(auto i :c)
  11. #define pii pair< int,int >
  12. #define fast_io() ios_base::sync_with_stdio(false);cin.tie(nullptr)
  13. #define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
  14. #define er(x) cout << x << " "
  15. #define err(x,y) cout << x << " "<<y
  16. const int M = 200005;
  17. using namespace std;
  18. using namespace std;
  19.  
  20. int main() {
  21. int n; cin >> n ;
  22. int a[2*n];
  23. for (int i= 0 ; i <n ; ++ i )
  24. {
  25. cin >>a[i];
  26. a[i+n]=a[i];
  27. }
  28.  
  29. int cs=0 , ms=0;
  30. for (int i= 0 ; i < n*2 ; ++ i )
  31. {
  32. if (a[i])
  33. cs+=a[i];
  34. else
  35. cs = 0 ;
  36.  
  37. ms=max(cs , ms );
  38.  
  39. }
  40.  
  41. er(ms);
  42. return 0;
  43. }
Success #stdin #stdout 0s 15232KB
stdin
3
0 0 0
stdout
0