Codeforces Round #694 (Div. 1) 1470A - Strange Birthday Party Solution

 


Problem Link: https://codeforces.com/problemset/problem/1470/A

Solve 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()
{
    long long n,m,i,j,t,cs;
    cin>>t;
    while(t--)
    {
        cs=0;
        cin>>n>>m;
        long long k[n],c[m],nc[n];
        for(i=1; i<=n; i++)cin>>k[i];
        for(i=1; i<=m; i++)cin>>c[i];
        for(i=1; i<=n; i++)
        {
            nc[i]=c[k[i]];
        }
        sort(nc+1,nc+n+1);
        j=1;
        for(i=n; i>0; i--)
        {
            if(c[j]<nc[i])
            {
                cs+=c[j];
                j++;
            }
            else
                cs+=nc[i];
        }
        cout<<cs<<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 &g...

Powered by Blogger.