Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int n;
- cin >> n;
- vector<int> a(n);
- for(int i = 0; i < n; ++i)
- cin >> a[i];
- int m;
- cin >> m;
- vector<int> p(1001, 1001);
- int ans = 0;
- for(int i = 0; i < m; ++i){
- int b, c;
- cin >> b >> c;
- p[b] = min(p[b], c);
- }
- for(int i = p.size() - 2; i > -1; --i){
- p[i] = min(p[i], p[i + 1]);
- }
- for(int i = 0; i < n; ++i){
- ans += p[a[i]];
- }
- cout << ans << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement