Source Code
/*
	Failure is not the reason for you to stop trying
	   it is actually a remainder that you should
			KEEP GOING
*/
#include<bits/stdc++.h>
#define ll long long
#define SaveTime ios_base::sync_with_stdio(false), cin.tie(0);
using namespace std;

int main()
{
   SaveTime
   int n,m; cin >> n >> m;
   pair<int,int> num[n];
   int nb[n+1];
   memset(nb, 0, sizeof nb);
   for (int i = 0; i < n; i++) {
      cin >> num[i].second;
      nb[num[i].second]++;
   }
   for (int i = 0; i < n; i++) {
      cin >> num[i].first;
   }
   for (int i = 0; i < m; i++) {
      int x; cin >> x;
      nb[x]--;
   }
   sort(num,num+n);
   ll ans = 0;
   for (int i = 0; i < n; i++) {
      if (nb[num[i].second] == 0)
         continue;
      if (num[i].first <= 0) {
         ans+= num[i].first;
         nb[num[i].second]--;
      }
   }
   cout << ans;
}
Copy
Always with Me, Always with You chaffar107
GNU G++17
210 ms
10.6 MB
Wrong Answer