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;

const int mx = 1e6+7;
int cost[mx];
int num[mx];

bool b(int a, int b) {

}

int main()
{
   SaveTime
   int n,m; cin >> n >> m;
   set<int> s;
   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;
      s.insert(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
681 ms
35.4 MB
Wrong Answer