Language: C++

using namespace std;
 
int main()
{
    int N, M, K;
    cin >> N >> M >> K;
    vector<long> A(N);
    vector<long> B(M);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }
    for (int i = 0; i < M; i++)
    {
        cin >> B.at(i);
    }
    long time = 0;
    int count = 0;
    int A_now = 0;
    int B_now = 0;
    for (int i = 0; i < N+M; i++)
    {
        if (time < K)
        {
            if (A_now < N && B_now < M)
            {
                if (A.at(A_now) <= B.at(B_now))
                {
                    if (time + A.at(A_now) <= K)
                    {
                        count++;
                        A_now++;
                    }
                }else
                {
                    if (time + B.at(B_now) <= K)
                    {
                        count++;
                        B_now++;
                    }
                }
            }else if (A_now < N)
            {
                if (A.at(A_now) <= B.at(B_now))
                {
                    if (time + A.at(A_now) <= K)
                    {
                        count++;
                        A_now++;
                    }
                }
            }else if (B_now < M)
            {
                 if (time + B.at(B_now) <= K)
                {
                    count++;
                    B_now++;
                }
            }else
            {
                break;
            }
        }else
        {
            count--;
            break;
        }
    }
    cout << count;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:6:5: error: 'cin' was not declared in this scope
    6 |     cin >> N >> M >> K;
      |     ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | using namespace std;
a.cc:7:5: error: 'vector' was not declared in this scope
    7 |     vector<long> A(N);
      |     ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | using namespace std;
a.cc:7:12: error: expected primary-expression before 'long'
    7 |     vector<long> A(N);
      |            ^~~~
a.cc:8:12: error: expected primary-expression before 'long'
    8 |     vector<long> B(M);
      |            ^~~~
a.cc:11:16: error: 'A' was not declared in this scope
   11 |         cin >> A.at(i);
      |                ^
a.cc:15:16: error: 'B' was not declared in this scope
   15 |         cin >> B.at(i);
      |                ^
a.cc:27:21: error: 'A' was not declared in this scope
   27 |                 if (A.at(A_now) <= B.at(B_now))
      |                     ^
a.cc:27:36: error: 'B' was not declared in this scope
   27 |                 if (A.at(A_now) <= B.at(B_now))
      |                                    ^
a.cc:44:21: error: 'A' was not declared in this scope
   44 |                 if (A.at(A_now) <= B.at(B_now))
      |                     ^
a.cc:44:36: error: 'B' was not declared in this scope
   44 |                 if (A.at(A_now) <= B.at(B_now))
      |                                    ^
a.cc:54:29: error: 'B' was not declared in this scope
   54 |                  if (time + B.at(B_now) <= K)
      |                             ^
a.cc:69:5: error: 'cout' was not declared in this scope
   69 |     cout << count;
      |     ^~~~
a.cc:69:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'