Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define all(x) begin(x),end(x)
- using namespace std;
- using ll = long long;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int n;
- ll m;
- cin >> n >> m;
- vector<pair<int, int>> a(n);
- for (int i = 0; i < n; i++) cin >> a[i].first;
- for (int i = 0; i < n; i++) cin >> a[i].second;
- /*
- (ans - 1) * sum_of_h + sum_of_a <= M
- */
- sort(all(a));
- int left = 1;
- int right = n;
- int mid;
- if (a[0].first > m) {
- cout << 0 << '\n';
- return 0;
- }
- int answer = 0;
- while (left <= right) {
- mid = (left + right) >> 1;
- vector<ll> b(n);
- for (int i = 0; i < n; i++) {
- auto& [x, y] = a[i];
- b[i] = x + y * 1ll * (mid - 1);
- }
- sort(all(b));
- ll cur = 0;
- for (int i = 0; i < mid; i++) {
- cur += b[i];
- }
- if (cur <= m) {
- answer = mid;
- left = mid + 1;
- } else {
- right = mid - 1;
- }
- }
- cout << answer << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement