Language: C++

#include <bits/stdc++.h>

using namespace std;

int main(){
	//~ freopen("input.txt", "r", stdin);
	//~ freopen("output.txt", "w", stdout);
	int n, m;
	long long k;
	scanf("%d %d %lld", &n, &m, &k);
	vector <long long> a(n);
	vector <long long> b(m);
	for (int i = 0; i < n; i++){
		scanf("%lld", &a[i]);
	}
	for (int i = 0; i < m; i++){
		scanf("%lld", &b[i]);
	}
	stack <long long> s;
	stack <lon glong> t;
	for (int i = n - 1; i >= 0; i--){
		s.push(a[i]);
	}
	for (int i = m - 1; i >= 0; i--){
		t.push(b[i]);
	}
	int ans = 0;
	while (k > 0){
		int x, y;
		bool flagx = false, flagy = false;
		if (!s.empty()){
			x = s.top();
			flagx = true;
		}
		if (!t.empty()){
			y = t.top();
			flagy = true;
		}
		if (flagx && flagy){
			if (x > y){
				t.pop();
				k -= y;
				if (k >= 0)
					ans++;
			}
			else if (x < y){
				s.pop();
				k -= x;
				if (k >= 0)
					ans++;
			}
			else {
				s.pop();
				t.pop();
				bool xx = false, yy = false;
				if (!s.empty()) xx = true;
				if (!t.empty()) yy = true;
				if (xx && yy){
					if (s.top() <= t.top()){
						t.push(x);
						k -= x;
						if (k >= 0)
							ans++;
					}
					else{
						s.push(x);
						k -= x;
						if (k >= 0)
							ans++;
					} 
				}
				else if (xx){
					if (s.top() <= x){
						t.push(x);
						k -= x;
						if (k >= 0)
							ans++;
					}
					else {
						s.push(x);
						k -= x;
						if (k >= 0)
							ans++;
					}
				}
				else if (yy){
					if (t.top() <= x){
						s.push(x);
						k -= x;
						if (k >= 0)
							ans++;
					}
					else {
						t.push(x);
						k -= x;
						if (k >= 0)
							ans++;
					}
				}
				else {
					s.push(x);
					k -= x;
					if (k >= 0)
						ans++;
				}
			}
		}
		else if (flagx){
			k -= s.top();
			s.pop();
			if (k >= 0)
				ans++;
		}
		else if (flagy){
			k -= t.top();
			t.pop();
			if (k >= 0)
				ans++;
		}
		else {
			break;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:20:16: error: 'lon' was not declared in this scope; did you mean 'long'?
   20 |         stack <lon glong> t;
      |                ^~~
      |                long
a.cc:20:25: error: template argument 1 is invalid
   20 |         stack <lon glong> t;
      |                         ^
a.cc:20:25: error: template argument 2 is invalid
a.cc:25:19: error: request for member 'push' in 't', which is of non-class type 'int'
   25 |                 t.push(b[i]);
      |                   ^~~~
a.cc:35:24: error: request for member 'empty' in 't', which is of non-class type 'int'
   35 |                 if (!t.empty()){
      |                        ^~~~~
a.cc:36:31: error: request for member 'top' in 't', which is of non-class type 'int'
   36 |                         y = t.top();
      |                               ^~~
a.cc:41:35: error: request for member 'pop' in 't', which is of non-class type 'int'
   41 |                                 t.pop();
      |                                   ^~~
a.cc:54:35: error: request for member 'pop' in 't', which is of non-class type 'int'
   54 |                                 t.pop();
      |                                   ^~~
a.cc:57:40: error: request for member 'empty' in 't', which is of non-class type 'int'
   57 |                                 if (!t.empty()) yy = true;
      |                                        ^~~~~
a.cc:59:58: error: request for member 'top' in 't', which is of non-class type 'int'
   59 |                                         if (s.top() <= t.top()){
      |                                                          ^~~
a.cc:60:51: error: request for member 'push' in 't', which is of non-class type 'int'
   60 |                                                 t.push(x);
      |                                                   ^~~~
a.cc:74:51: error: request for member 'push' in 't', which is of non-class type 'int'
   74 |                                                 t.push(x);
      |                                                   ^~~~
a.cc:87:47: error: request for member 'top' in 't', which is of non-class type 'int'
   87 |                                         if (t.top() <= x){
      |                                               ^~~
a.cc:94:51: error: request for member 'push' in 't', which is of non-class type 'int'
   94 |                                                 t.push(x);
      |                                                   ^~~~
a.cc:115:32: error: request for member 'top' in 't', which is of non-class type 'int'
  115 |                         k -= t.top();
      |                                ^~~
a.cc:116:27: error: request for member 'pop' in 't', which is of non-class type 'int'
  116 |                         t.pop();
      |                           ^~~