Source Code
#include<bits/stdc++.h>
#include <iostream>
#include<map>
using namespace std;
int main() {
int n,m;
cin>>n>>m;
vector<long long>a;
vector<pair<long long,long long>>b;
long long v;
for(int i=0;i<n;i++)
{
	cin>>v;
	a.push_back(v);
}
for(int i=0;i<n;i++)
{
	cin>>v;

		b.push_back(make_pair(v,a[i]));
}
sort(b.begin(),b.end());
reverse(b.begin(),b.end());
map<long long,long long>c;
for(int i=0;i<m;i++)
{
	cin>>v;
	c[v]=1;
}
long long s=0;
for(int i=0;i<n;i++)
{
	if(c[b[i].second]!=1&&b[i].first<0)
		s+=b[i].first;
	else
		c[b[i].second]=0;
}
cout<<s;
	return 0;
}
Copy
Always with Me, Always with You sameh58
GNU G++17
1081 ms
53.6 MB
Wrong Answer