Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define ull unsigned long long
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- ll n, m;
- cin >> n >> m;
- vector<ll>items(n);
- map<ll,ll>mp;
- for (int i=0; i<n; i++) {
- cin >> items[i];
- mp[items[i]]++;
- }
- vector<ll>cars(m);
- for (int i=0; i<m; i++) {
- cin >> cars[i];
- }
- vector<vector<ll>>v(m);
- sort(items.begin(), items.end());
- sort(cars.rbegin(), cars.rend());
- ll ans=0;
- while (!mp.empty()) {
- auto x=--mp.rbegin();
- int i=0;
- while (i<m) {
- if (x->first<=cars[i]) {
- i++;
- if (x->second>1) x->second--;
- else mp.erase(x->first);
- if (mp.empty()) break;
- }
- else if (x!=mp.rend()) x++;
- else break;
- }
- ans+=2;
- }
- ans--;
- cout << ans << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment