Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <vector>
- #include <set>
- #include <map>
- #include <sstream>
- #include <cstdio>
- #include <algorithm>
- #include <stack>
- #include <queue>
- #include <cmath>
- #include <iomanip>
- #include <fstream>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- int n;
- cin>>n;
- int prof=0;
- vector <int>a(n);
- for (int i=0;i<n;i++){
- cin>> a[i];
- }
- sort (a.begin(),a.end());
- int b[n],c[n];
- vector<pair<int, int> > v;
- for (int i=0;i<n;i++){
- cin>>b[i];
- cin>>c[i];
- v.push_back(make_pair (c[i],b[i]));
- }
- sort (v.begin(),v.end());
- cout << endl;
- for (int i=n-1;i>=0;i--){
- int left_bound = 0;
- int right_bound = (int) a.size() - 1;
- int it = -1;
- while(left_bound <= right_bound) {
- int middle = (left_bound + right_bound) / 2;
- if(a[middle] > v[i].second) {
- right_bound = middle - 1;
- }
- else {
- left_bound = middle + 1;
- it = middle;
- }
- }
- if(it != -1) {
- a.erase(a.begin() + it);
- prof += v[i].first;
- }
- }
- cout<<prof << endl;
- }
- // 412137702
- // 412137702
Advertisement
Add Comment
Please, Sign In to add comment