Vadimchik133's blog

By Vadimchik133, history, 2 hours ago, In Russian

include <bits/stdc++.h>

using namespace std;

void solve(){ int64_t n, k; cin >> n >> k; vector arr(n); map<int64_t, int64_t> mp; for (int i = 0; i < n; i++){ cin >> arr[i]; mp[arr[i]]++; } int64_t ans = 0; for (int i = 0; i < k; i++){ int64_t sm; cin >> sm; auto x = mp.lower_bound(sm); bool fl = false; while (sm > 0){ int64_t z = mp[(*x).first]; int64_t penis = sm / (*x).first; sm -= min(z, penis) * (*x).first; ans += min(z, penis); if (sm > 0){ if (x == mp.begin()) { fl = true; break; } x = prev(x); } } if (fl) cout << -1 << endl; else cout << ans << endl; }

}

int main(){ int t = 1; //cin >> t; while (t--){ solve(); } }

  • Vote: I like it
  • 0
  • Vote: I do not like it