Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef int ll;
- typedef vector<ll> line;
- int main() {
- int n, m, w;
- cin >> n >> m >> w;
- multiset<int> unused;
- multiset<int> used;
- line note(m);
- for (int i = 0; i < n; ++i) {
- int x;
- cin >> x;
- unused.insert(x);
- }
- for (auto &y : note) {
- cin >> y;
- }
- int ans = 0;
- for (int i = 0; i < m; ++i) {
- if (used.count(note[i]) != 0) {
- ans++;
- continue;
- }
- auto bot = unused.upper_bound(note[i]);
- if (bot == unused.begin()) {
- cerr << "1 break;\n";
- break;
- }
- bot--;
- int cnt = *bot;
- if (w < note[i] - cnt) {
- cerr << "2 break\n";
- break;
- }
- unused.erase(bot);
- used.insert(note[i]);
- w -= note[i] - cnt;
- ans++;
- }
- cout << ans << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement