Advertisement
deushiro

Untitled

Jan 7th, 2020
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6.  
  7. int main()
  8. {
  9.     ios_base::sync_with_stdio(false);
  10.     cin.tie(0);
  11.     cout.tie(0);
  12.     int n;
  13.     cin >> n;
  14.     vector<int> a(n);
  15.     for(int i = 0; i < n; ++i)
  16.         cin >> a[i];
  17.     int m;
  18.     cin >> m;
  19.     vector<int> p(1001, 1001);
  20.     int ans = 0;
  21.     for(int i = 0; i < m; ++i){
  22.         int b, c;
  23.         cin >> b >> c;
  24.         p[b] = min(p[b], c);
  25.     }
  26.     for(int i = p.size() - 2; i > -1; --i){
  27.         p[i] = min(p[i], p[i + 1]);
  28.     }
  29.     for(int i = 0; i < n; ++i){
  30.         ans += p[a[i]];
  31.     }
  32.     cout << ans << endl;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement