fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int MaxN = (int)1e5 + 10;
  6. const int INF = (int)1e9;
  7. const int MOD = 998244353;
  8.  
  9. int n, a[MaxN], b[MaxN];
  10. long long m;
  11.  
  12. bool chk(long long val) {
  13. // max(0, a[i]-x)*b[i] <= val
  14. long long ans = 0LL;
  15. for (int i = 1; i <= n; ++i) {
  16. if (b[i] != 0) {
  17. //(a[i]-x) <= val/b[i]
  18. //a[i]-val/b[i] <= x
  19. ans += max(0LL, a[i] - val / b[i]);
  20. if (ans > m) {
  21. ans = m + 1;
  22. }
  23. }
  24. }
  25. return ans <= m;
  26. }
  27.  
  28. int main() {
  29. // freopen("input.txt", "r", stdin);
  30. scanf("%d%lld", &n, &m);
  31. assert (1 <= n && n <= 1e5);
  32. assert (0 <= m && m <= 1e18);
  33. for (int i = 1; i <= n; ++i) {
  34. scanf("%d", &a[i]);
  35. assert (0 <= a[i] && a[i] <= INF);
  36. }
  37. for (int i = 1; i <= n; ++i) {
  38. scanf("%d", &b[i]);
  39. assert (0 <= b[i] && b[i] <= INF);
  40. }
  41. long long l = 0, r = 1e18, ans = 1e18 + 1;
  42. while (l <= r) {
  43. long long md = (l + r) / 2;
  44. if (chk(md)) {
  45. ans = md;
  46. r = md - 1;
  47. } else {
  48. l = md + 1;
  49. }
  50. }
  51. cout << ans << "\n";
  52. return 0;
  53. }
  54.  
Runtime error #stdin #stdout #stderr 0s 16016KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
prog: prog.cpp:31: int main(): Assertion `1 <= n && n <= 1e5' failed.