fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. int main()
  5. {
  6. ll t;
  7. cin>>t;
  8. for(ll i=0;i<t;i++)
  9. {
  10. ll n,m,k,l,o,p;
  11. cin>>n>>m>>k;
  12. ll a[n+1],b[m+1];
  13. a[0]=0,b[0]=0;
  14. for(ll i=1;i<=n;i++)
  15. {
  16. ll x,y;
  17. cin>>x;
  18. a[i]=x+a[i-1];
  19. }
  20. for(ll i=1;i<=m;i++)
  21. {
  22. ll x,y;
  23. cin>>x;
  24. b[i]=x+b[i-1];
  25. }
  26. o=1;
  27. p=m;
  28. while((o<=n)&&(p<=m)){
  29. if(a[o]+b[p]>k){
  30. p--;
  31. if(p==0){
  32. p=m;
  33. o++;
  34. }
  35. }else{
  36. break;
  37. }
  38. }
  39. cout<<o+p<<"\n";
  40. }
  41.  
  42. }
  43.  
Runtime error #stdin #stdout 0s 4288KB
stdin
Standard input is empty
stdout
Standard output is empty