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 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.