fork download
  1. #include <bits/stdc++.h>
  2. #define FOR(i, l, r) for (int i = l; i <= r; ++i)
  3. #define FOD(i, r, l) for (int i = r; i >= l; --i)
  4. #define ll long long
  5. #define ep emplace_back
  6. #define fi first
  7. #define se second
  8. #define pli pair <ll, int>
  9. #define NAME ""
  10. #define all(x) x.begin(), x.end()
  11. using namespace std;
  12.  
  13. const int N = 5e5 + 5;
  14. const ll INF = 2e9;
  15.  
  16. int n;
  17. ll t[N], f[N];
  18. priority_queue <ll> pq;
  19.  
  20. signed main()
  21. {
  22. ios_base::sync_with_stdio(false);
  23. cin.tie(NULL);
  24. if (fopen(NAME".INP", "r"))
  25. {
  26. freopen(NAME".INP", "r", stdin);
  27. freopen(NAME".OUT", "w", stdout);
  28. }
  29. cin >> n;
  30. FOR(i, 1, n) cin >> t[i];
  31. FOR(i, 1, n) cin >> f[i];
  32. ll D = 0;
  33. FOR(i, 1, n)
  34. {
  35. if (D <= t[i])
  36. {
  37. pq.push(f[i]);
  38. D += f[i];
  39. }
  40. else
  41. {
  42. ll fj = pq.top();
  43. if (fj > f[i])
  44. {
  45. pq.pop();
  46. D = D - fj + f[i];
  47. pq.push(f[i]);
  48. }
  49. }
  50. }
  51. cout << pq.size();
  52. return 0;
  53. }
  54.  
Success #stdin #stdout 0.01s 5676KB
stdin
6
1 1 2 2 4 8
2 2 3 5 2 2
stdout
3