Codeforces Round #783 (Div. 2) 1668C. Make it Increasing Solution




Problem Link:  https://codeforces.com/contest/1668/problem/C 

Solution in C++: 

///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
///**********ALLAH IS ALMIGHTY************///
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n,i,j,next,sum,ans=1e18,mov;
    cin>>n;
    ll a[n+9];
    for(i=1; i<=n; i++)cin>>a[i];
    for(i=1; i<=n; i++)
    {
        next=0,sum=0;
        for(j=i+1; j<=n; j++)
        {
            mov=next/a[j];
            sum+=mov+1;
            next=(mov+1)*a[j];
        }
        next=0;
        for(j=i-1; j>=1; j--)
        {
            mov=next/a[j];
            sum+=mov+1;
            next=(mov+1)*a[j];
        }
        ans=min(ans,sum);
    }
    cout<<ans<<endl;
}







No comments

Most View Post

Recent post

RESTful APIs with CRUD Operations in Laravel 12| (2025)

  RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

Powered by Blogger.