Advertisement
LEGEND2004

Integer Cards

Aug 3rd, 2023
1,037
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5. #define pb push_back
  6.  
  7. signed main()
  8. {
  9.     int n , m , k , b , c;
  10.     cin >> n >> m;
  11.     set<int> s;
  12.     map<int , int> cnt;
  13.     for(int i = 0; i < n; i++){
  14.         cin >> k;
  15.         s.insert(k);
  16.         cnt[k]++;
  17.     }
  18.     while(m--){
  19.         cin >> b >> c;
  20.         s.insert(c);
  21.         cnt[c] += b;
  22.     }
  23.     auto it = s.end();
  24.     it--;
  25.     int p , l , ans = 0;
  26.     while(it != s.begin()){
  27.         l = *it;
  28.         p = min(n , cnt[l]);
  29.         ans += (p * l);
  30.         n -= p;
  31.         it--;
  32.     }
  33.     l = *it;
  34.     p = min(n , cnt[l]);
  35.     ans += (p * l);
  36.     cout << ans << endl;
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement