Advertisement
999ms

Untitled

Aug 6th, 2020
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define all(x) begin(x),end(x)
  3.  
  4. using namespace std;
  5. using ll = long long;
  6.  
  7. int main() {
  8. ios_base::sync_with_stdio(false);
  9. cin.tie(nullptr);
  10. cout.tie(nullptr);
  11. int n;
  12. ll m;
  13. cin >> n >> m;
  14. vector<pair<int, int>> a(n);
  15. for (int i = 0; i < n; i++) cin >> a[i].first;
  16. for (int i = 0; i < n; i++) cin >> a[i].second;
  17. /*
  18. (ans - 1) * sum_of_h + sum_of_a <= M
  19. */
  20. sort(all(a));
  21. int left = 1;
  22. int right = n;
  23. int mid;
  24. if (a[0].first > m) {
  25. cout << 0 << '\n';
  26. return 0;
  27. }
  28. int answer = 0;
  29. while (left <= right) {
  30. mid = (left + right) >> 1;
  31. vector<ll> b(n);
  32. for (int i = 0; i < n; i++) {
  33. auto& [x, y] = a[i];
  34. b[i] = x + y * 1ll * (mid - 1);
  35. }
  36. sort(all(b));
  37. ll cur = 0;
  38. for (int i = 0; i < mid; i++) {
  39. cur += b[i];
  40. }
  41. if (cur <= m) {
  42. answer = mid;
  43. left = mid + 1;
  44. } else {
  45. right = mid - 1;
  46. }
  47. }
  48. cout << answer << '\n';
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement