Language: C++

// Created by Kshitij Anand NSIT
#include <bits/stdc++.h>
//#include <ext/numeric>
//using namespace __gnu_cxx;


using namespace std;


#define int long long
#define pb push_back
#define P pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define mp(a, b) make_pair(a, b)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define fill(arr,val) memset(arr,val,sizeof(arr))
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define db(x)  cout<<#x<<" : "<<x<<endl


const int N = 1000000007;

int arr1[200001];
int arr2[200001];

int dp[200001][200001];

int n , m;

int func(int curr1 , int curr2 , int time ){

    if(time <= 0) return 0;

    if(curr1 >= n && curr2 >=m) return 0;

    if(dp[curr1][curr2] !=-1)  return dp[curr1][curr2];

    int ans;

    if(curr1 >=n && arr2[curr2] <= time){
        ans = 1 + func(curr1 , curr2 + 1 , time - arr2[curr2]);
        return ans;

    }

    if(curr2 >=m && arr1[curr1] <= time){
        ans = 1 + func(curr1 + 1 , curr2 , time - arr1[curr1]);
        return ans;
    }

    ans = 1 + min(func(curr1 , curr2 + 1 , time - arr2[curr2]) , func(curr1 + 1 , curr2 , time - arr1[curr1]));

    dp[curr1][curr2] = ans;
    return ans;

}

void solve(){

    int a,b,c, ans=0, count=0, sum=0;
    cin>>n>>m>>b;
    fill(dp , -1);
    for(int i=0;i<n;i++){
      cin>>arr1[i];
    }

    for(int i=0;i<m;i++){
      cin>>arr2[i];
    }

    ans = func(0 ,0 , b);

    // int i = 0;
    // int j = 0;

    // while(i <n && j<m && b >=0){

    //     if(arr1[i] < arr2[j] && arr1[i] <= b){
    //         ans++;
    //         b -= arr1[i];
    //         i++;
    //     }

    //     else if(arr1[i] >= arr2[j] && arr2[j] <= b){
    //         ans++;
    //         b -= arr2[j];
    //         j++;
    //     }

    //     else{
    //         break;
    //     }

    // }

    // while(i <n && b >= 0){

    //     if(arr1[i] <=b){
    //         ans++;
    //         b-= arr1[i];
    //         i++;
    //     }

    //     else{
    //         break;
    //     }
    // } 

    // while(j <m && b >= 0){

    //     if(arr2[j] <=b){
    //         ans++;
    //         b-= arr2[j];
    //         j++;
    //     }

    //     else{
    //         break;
    //     }
    // }

    cout<<ans<<endl;
}


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    
  //  int t; cin>>t; while(t--)
    {     
      solve();
    }

  return 0;
}


Compiler output:
/tmp/ccWfPYAQ.o: in function `func(long long, long long, long long)':
a.cc:(.text+0x28): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccWfPYAQ.o
a.cc:(.text+0x35): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccWfPYAQ.o
a.cc:(.text+0xa1): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccWfPYAQ.o
a.cc:(.text+0x111): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccWfPYAQ.o
/tmp/ccWfPYAQ.o: in function `solve()':
a.cc:(.text+0x260): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccWfPYAQ.o
a.cc:(.text+0x27c): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccWfPYAQ.o
a.cc:(.text+0x2f8): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccWfPYAQ.o
a.cc:(.text+0x33c): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccWfPYAQ.o
collect2: error: ld returned 1 exit status