Codeforces Round #473 (Div. 2), problem: (B) Mahmoud and Ehab and the message Solution In C/C++

#include<bits/stdc++.h>
using namespace std;
map<string,int> ms;
string str;
int arr[100005],temp[100005],mn[100005];
int main()
{
int n,k,m;cin>>n>>k>>m;
for(int i=1;i<=n;i++)cin>>str,ms[str]=i;
for(int i=1;i<=n;i++)cin>>arr[i],mn[i]=1e9+7;
for(int i=1,j;i<=k;i++)
{
int x;cin>>x;
while(x–)cin>>j,temp[j]=i,mn[i]=min(mn[i],arr[j]);
}
unsigned long long res=0;
while(cin>>str){res+=mn[temp[ms[str]]];}
return cout<<res<<“\n”,0;
}

#include<bits/stdc++.h>
using namespace std;
map<string,int> ms;
string str;
int arr[100005],temp[100005],mn[100005];
int main()
{
int n,k,m;cin>>n>>k>>m;
for(int i=1;i<=n;i++)cin>>str,ms[str]=i;
for(int i=1;i<=n;i++)cin>>arr[i],mn[i]=1e9+7;
for(int i=1,j;i<=k;i++)
{
int x;cin>>x;
while(x–)cin>>j,temp[j]=i,mn[i]=min(mn[i],arr[j]);
}
unsigned long long res=0;
while(cin>>str){res+=mn[temp[ms[str]]];}
return cout<<res<<“\n”,0;
}

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

Why Viral Kitchen Gadgets Is Currently Breaking the Internet

📢 As an Amazon Associate, I earn from qualifying purchases.After putting the Viral Kitchen Gadgets through a proper 30-day real-world test, I can tell...

‘Game-changer’ thermal drones uncover threatened whio in Tongariro river

Conservation efforts in New Zealand have reached an exciting new frontier as cutting-edge thermal imaging drones prove to be a massive game-changer for monitoring...

Is Viral Kitchen Gadgets Worth Your Money Here Is Our Full Review

📢 As an Amazon Associate, I earn from qualifying purchases.There comes a point when you realise that tolerating a frustrating situation is costing you...

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!