Advertisement
Guest User

Untitled

a guest
Nov 25th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef int ll;
  6. typedef vector<ll> line;
  7.  
  8. int main() {
  9.  
  10.     int n, m, w;
  11.     cin >> n >> m >> w;
  12.     multiset<int> unused;
  13.     multiset<int> used;
  14.     line note(m);
  15.     for (int i = 0; i < n; ++i) {
  16.         int x;
  17.         cin >> x;
  18.         unused.insert(x);
  19.     }
  20.     for (auto &y : note) {
  21.         cin >> y;
  22.     }
  23.     int ans = 0;
  24.     for (int i = 0; i < m; ++i) {
  25.         if (used.count(note[i]) != 0) {
  26.             ans++;
  27.             continue;
  28.         }
  29.         auto bot = unused.upper_bound(note[i]);
  30.         if (bot == unused.begin()) {
  31.             cerr << "1 break;\n";
  32.             break;
  33.         }
  34.         bot--;
  35.         int cnt = *bot;
  36.  
  37.         if (w < note[i] - cnt) {
  38.             cerr << "2 break\n";
  39.             break;
  40.         }
  41.  
  42.         unused.erase(bot);
  43.         used.insert(note[i]);
  44.         w -= note[i] - cnt;
  45.         ans++;
  46.     }
  47.     cout << ans << "\n";
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement