Codeforces Round #772 (Div. 2 ) 1635B - Avoid Local Maximums Solution



Problem Link : https://codeforces.com/contest/1635/problem/B

 Solution in C++: 

///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include <bits/stdc++.h>
using namespace std;
int a[500005];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int  t,n,i,c;
    cin>>t;
    while(t--)
    {
        c=0;
        cin>>n;
        for( i=1; i<=n; i++)
        {
            cin>>a[i];
        }
        for(i=2; i<=n-1; i++)
        {
            if(a[i]>a[i-1]&&a[i]>a[i+1])
            {
                a[i+1]=max(a[i],a[i+2]);
                c++;
            }
        }
        cout<<c<<endl;
        for(i=1; i<=n; i++)
        {
            cout<<a[i]<<" ";
        }
        cout<<endl;
    }
}




No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.