Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- #define pb push_back
- signed main()
- {
- int n , m , k , b , c;
- cin >> n >> m;
- set<int> s;
- map<int , int> cnt;
- for(int i = 0; i < n; i++){
- cin >> k;
- s.insert(k);
- cnt[k]++;
- }
- while(m--){
- cin >> b >> c;
- s.insert(c);
- cnt[c] += b;
- }
- auto it = s.end();
- it--;
- int p , l , ans = 0;
- while(it != s.begin()){
- l = *it;
- p = min(n , cnt[l]);
- ans += (p * l);
- n -= p;
- it--;
- }
- l = *it;
- p = min(n , cnt[l]);
- ans += (p * l);
- cout << ans << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement