Codeforces Round #485 (Div. 2) 987C - Three displays Solution
Problem Link: https://codeforces.com/problemset/problem/987/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>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n,i,j,ans,curv,INF=50000000000;
while(cin>>n)
{
INF=50000000000;
long long s[n+9],c[n+9],d[n+9];
for(i=0; i<n; i++)cin>>s[i];
for(i=0; i<n; i++)cin>>c[i];
for(i=0; i<n; i++)
{
d[i]=INF;
for(j=i+1; j<n; j++)
{
if(s[i]<s[j])
{
d[i]=min(d[i],c[i]+c[j]);
}
}
}
ans=INF;
for(i=0; i<n; i++)
{
curv=INF;
for(j=i+1; j<n; j++)
{
if(s[i]<s[j])
{
curv=min(curv,d[j]+c[i]);
}
}
ans=min(ans,curv);
}
cout<<(ans==INF?-1:ans)<<endl;
}
}
No comments