fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long int
  3. #define endl "\n"
  4. #define pb push_back
  5. #define lb lower_bound
  6. #define ub upper_bound
  7. #define in insert
  8. #define ump unordered_map
  9. #define yes cout<<"Yes"<<"\n"
  10. #define no cout<<"No"<<"\n"
  11. const ll M = 998244353;
  12. const ll INF = LLONG_MAX;
  13. const int dx[] = {-1, 1, 0, 0};
  14. const int dy[] = {0, 0, -1, 1};
  15. using namespace std;
  16. const int N = 2e5+10;
  17.  
  18. int main() {
  19. ios_base::sync_with_stdio(false);
  20. cin.tie(0);
  21. ll n;cin>>n;
  22. vector<ll> ind(n);
  23. for(ll i=0;i<n;i++) cin>>ind[i];
  24. ump<ll,vector<ll>> mp;
  25. for(ll i=0;i<n;i++) {
  26. ll x;cin>>x;mp[ind[i]].pb(x);
  27. }
  28. for(auto &element: mp) {
  29. sort(element.second.begin(),element.second.end());
  30. }
  31. ll ct=0;
  32. for(auto &element: mp) {
  33. for(ll i=0;i<element.second.size()-1;i++) {
  34. // cout<<element.second[i]<<" ";
  35. ct+=element.second[i];
  36. }
  37. }
  38. cout<<ct<<endl;
  39. }
Success #stdin #stdout 0s 5320KB
stdin
12
3 6 7 4 12 4 8 11 11 1 8 11
3925 9785 9752 3587 4013 1117 3937 7045 6437 6208 3391 6309
stdout
17254