1117A - Best Subsegment - CodeForces Solution


implementation math *1100

Please click on ads to support us..

Python Code:

input()
a=[*map(int,input().split())]
m=max(a)
r=l=0
for x in a:
 if x<m:l=0
 else:l+=1;r=max(r,l)
print(r)
      				 					  			  		    		

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    int a[n];
    int maxi = -1;
    for (int i = 0; i < n; i++)
    {

        cin >> a[i];
        if (a[i] > maxi)
        {
            maxi = a[i];
        }
    }
    int length=0;
    int p=0,q=0;

    for (int i = 0; i < n; i++)
    {
        if (a[i]==maxi && q==0)
        {
            q=1;
            p=i;

        }
        else if(a[i]!=maxi && q==1) {
            q=0;
            length=max(length,i-p);
        }
        if(i==n-1 && a[i]==maxi && q==1){
            length=max(length,i-p+1);
        }
    }
    
    cout<<length<<endl;
}


Comments

Submit
0 Comments
More Questions

1647D - Madoka and the Best School in Russia
1208A - XORinacci
1539B - Love Song
22B - Bargaining Table
1490B - Balanced Remainders
264A - Escape from Stones
1506A - Strange Table
456A - Laptops
855B - Marvolo Gaunt's Ring
1454A - Special Permutation
1359A - Berland Poker
459A - Pashmak and Garden
1327B - Princesses and Princes
1450F - The Struggling Contestant
1399B - Gifts Fixing
1138A - Sushi for Two
982C - Cut 'em all
931A - Friends Meeting
1594A - Consecutive Sum Riddle
1466A - Bovine Dilemma
454A - Little Pony and Crystal Mine
2A - Winner
1622B - Berland Music
1139B - Chocolates
1371A - Magical Sticks
1253A - Single Push
706B - Interesting drink
1265A - Beautiful String
214A - System of Equations
287A - IQ Test