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