fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define pb push_back
  4. #define arr array
  5.  
  6. using namespace std;
  7.  
  8. const int e = 2e6 + 69;
  9. const ll mod = 1e9 + 7;
  10.  
  11. ll a[e], b[e];
  12.  
  13. //beginner 1999 128
  14.  
  15.  
  16. int main()
  17. {
  18. int n, m;
  19. ll k;
  20. cin >> n >> m >> k;
  21. ll s = 0;
  22. for(int i=1; i<=n; i++){
  23. cin >> a[i];
  24. s += a[i];
  25. }
  26. for(int i=1; i<=m; i++){
  27. cin >> b[i];
  28. s += b[i];
  29. }
  30. if(s <= k){
  31. cout << n + m;
  32. return 0;
  33. }
  34. int pos1 = 1, pos2 = 1;
  35. a[n+1] = 1e17;
  36. b[m+1] = 1e18;
  37. int dem = 0;
  38. while(k - min(a[pos1], b[pos2]) >= 0){
  39. dem ++;
  40. k -= min(a[pos1], b[pos2]);
  41. if(min(a[pos1], b[pos2]) == a[pos1]){
  42. pos1 ++;
  43. }
  44. else{
  45. pos2 ++;
  46. }
  47. }
  48. cout << dem;
  49. }
Runtime error #stdin #stdout 0.02s 4500KB
stdin
Standard input is empty
stdout
Standard output is empty