josiftepe

Untitled

Oct 17th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <vector>
  4. #include <set>
  5. #include <map>
  6. #include <sstream>
  7. #include <cstdio>
  8. #include <algorithm>
  9. #include <stack>
  10. #include <queue>
  11. #include <cmath>
  12. #include <iomanip>
  13. #include <fstream>
  14. using namespace std;
  15.  
  16. int main() {
  17.     ios_base::sync_with_stdio(false);
  18.     ifstream cin("in.txt");
  19.     int n;
  20.     cin>>n;
  21.     int prof=0;
  22.     vector <int>a(n);
  23.     for (int i=0;i<n;i++){
  24.         cin>> a[i];
  25.     }
  26.     sort (a.begin(),a.end());
  27.     int b[n],c[n];
  28.     vector<pair<int, int> > v;
  29.     for (int i=0;i<n;i++){
  30.         cin>>b[i];
  31.         cin>>c[i];
  32.         v.push_back(make_pair (c[i],b[i]));
  33.     }
  34.     sort (v.begin(),v.end());
  35.     cout << endl;
  36.     for (int i=n-1;i>=0;i--){
  37.         int left_bound = 0;
  38.         int right_bound = (int) a.size() - 1;
  39.         int it = -1;
  40.         while(left_bound <= right_bound) {
  41.             int middle = (left_bound + right_bound) / 2;
  42.             if(a[middle] > v[i].second) {
  43.                 right_bound = middle - 1;
  44.             }
  45.             else {
  46.                 left_bound = middle + 1;
  47.                 it = max(it, middle);
  48.             }
  49.         }
  50.         if(it != -1) {
  51.             a.erase(a.begin() + it);
  52.             prof += v[i].first;
  53.         }
  54.        
  55.        
  56.     }
  57.  
  58.  
  59.  
  60.  
  61. cout<<prof << endl;
  62. }
  63. // 412137702
  64. // 412137702
  65.  
Advertisement
Add Comment
Please, Sign In to add comment