Advertisement
Rofyda_Elghadban1

Untitled

Oct 2nd, 2023
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1.  #include <bits/stdc++.h>
  2.  #define ll long long
  3.  #define ull unsigned long long
  4.  #define pi 3.141592654
  5.  #define NUM 1e18
  6.  #define Mod  1'000'000'007
  7.  #define fixed(n) fixed<<setprecision(n)
  8.  #define cin(v) for(auto &i:v) cin >> i ;
  9.  #define cout(v) for(auto &i:v) cout << i  <<" ";
  10.  #define vowel(x) (x=='e'||x=='a'||x=='i'||x=='o'||x=='u')
  11.  #define small(x) (x>=97&&x<=122)
  12.  #define capital(x) (x>=65&&x<=90)
  13.  #define Tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
  14.  #define Toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
  15.  #define all(v) ((v).begin()), ((v).end())
  16.  #define allr(v) ((v).rbegin()), ((v).rend())
  17.  #define updmax(a,b) a=max(a,b)
  18.  #define updmin(a,b) a=min(a,b)
  19.  #define ceil(a,b) ((a/b)+(a%b?1:0))
  20.  /* asc -> 1 2 3 ,des -> 3 2 1 */
  21.  /***********************************************************************************/
  22.  using namespace std;
  23.  void Rofyda_Elghadban(){
  24.   #ifndef ONLINE_JUDGE  
  25.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  26.    #endif
  27.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  28.  }
  29.  
  30.  struct com{
  31.   bool operator()(int l,int r){
  32.     return (l>=50)<(r>=50);
  33.   }
  34.  };
  35.  
  36.  void solve(){
  37.   int n,sum=0,counter=0,e=0,maxi1=INT_MIN,maxi2=INT_MIN,ans=0;
  38.   cin>>n;
  39.   vector<int>v(n),m,p;
  40.   cin(v);
  41.   for(int i=0;i<n;i++){
  42.     for(int j=i;j<n;j++){
  43.       sum+=v[j];
  44.       if(sum<0){
  45.         maxi1=max(maxi1,ans);
  46.         sum=0;
  47.         ans=0;
  48.       }else{
  49.         ans++;
  50.       }
  51.     }
  52.     for(int k=0;k<i;k++){
  53.       sum+=v[k];
  54.       if(sum<0){
  55.         maxi2=max(maxi2,ans);
  56.         sum=0;
  57.         ans=0;
  58.       }else{
  59.         ans++;
  60.       }
  61.     }
  62.   }
  63.   if((maxi1+maxi2)>n){
  64.     cout<<(maxi1+maxi2)/2<<"\n";
  65.   }else{
  66.     cout<<maxi1+maxi2<<"\n";
  67.   }
  68.  }
  69.  
  70.  int main(){
  71.   Rofyda_Elghadban();
  72.   solve();
  73.  
  74.   return 0;
  75.  }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement