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

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 ...

Powered by Blogger.