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

Affiliate Disclosure: This post contains Amazon affiliate links. If you purchase through these links, eBlogarithm may earn a commission at no extra cost to you. Prices and availability are subject to change.

#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;
}

📦 Looking for Codeforces Round 473 Div Problem Mahmoud? Check the best deals on Amazon.

🛒 Shop Codeforces Round 473 Div Problem Mahmoud on Amazon

As an Amazon Associate, eBlogarithm earns from qualifying purchases. Prices and availability are subject to change.

Affiliate Disclosure: This post contains Amazon affiliate links. If you purchase through these links, eBlogarithm may earn a commission at no extra cost to you. Prices and availability are subject to change.

#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;
}

📦 Looking for Codeforces Round 473 Div Problem Mahmoud? Check the best deals on Amazon.

🛒 Shop Codeforces Round 473 Div Problem Mahmoud on Amazon

As an Amazon Associate, eBlogarithm earns from qualifying purchases. Prices and availability are subject to change.

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

Yongxing YogasuitFactory Seamless Thermal Underwear For Winter

When winter arrives, dressing for the freezing weather often feels like an uncomfortable compromise between staying warm and retaining natural freedom of movement. Bulky...

How Viral Kitchen Gadgets Is Quietly Changing the Game

📢 As an Amazon Associate, I earn from qualifying purchases.I stumbled across this while desperately trying to fix a recurring problem in my routine....

Lil Durk Found Not Guilty in Federal Murder-for-Hire Trial

In a dramatic conclusion to one of the hip-hop community's most closely watched legal battles, Chicago rapper Lil Durk has been found not guilty...

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!