Problem:


Score : 300 points

Problem Statement

We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.

It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).

Consider the following action:

Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.

How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

Output

Print an integer representing the maximum number of books that can be read.

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

In this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd books from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st, 2-nd, 3-rd, 4-th books from the top on Desk B, respectively.

We can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.

Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.

Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.

Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000

Sample Output 3

0

Watch out for integer overflows.



Sample input:
3 4 240
60 90 120
80 150 80 150


Sample output:
3

Submission status: Runtime Error

Solution code:
def read(a, b, i, j, k):
    if i < len(a) and j < len(b) and a[i] <= k and b[j] <= k:
        return 1 + max(read(a, b, i+1, j, k-a[i]), read(a, b, i, j+1, k-b[j]))
    elif i < len(a) and a[i] <= k:
        return 1 + read(a, b, i+1, j, k-a[i])
    elif j < len(b) and b[j] <= k:
        return 1 + read(a, b, i, j+1, k-b[j])
    return 0


n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(read(a, b, 0, 0, k))

Submission status: Runtime Error

Solution code:
str = input()
lst = str.split(' ')
n,m,k = lst
n = int(n)
m = int(m)
k = int(k)
str1 = input()
str2 = input()
a = str1.split(' ')
b = str2.split(' ')
i=0
j=0
count = 0
while c<=k:
  c = c+int(a[i])
  if c<=k:
    a.pop(i)
    i = i+1
    count = count+1
  else:
    c = c-int(a[i])
  c = c+int(b[j])
  if c<=k:
    b.pop(j)
    j = j+1
    count = count+1
  else:
    c = c-int(b[j])
print(count)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())

A = list(map(int, input().split()))
B = list( map(int, input().split()) )

books = 0

p1 = 0
p2 = 0

while K > 0 and ( p1 < N or p2 < M ):
    books += 1

    if p1 < N and A[p1] < B[p2]:
        # print("chosen", "p1", p1)
        K -= A[p1]
        p1 += 1

    elif p2 < M:
        # print("chosen", "p2", p2)
        K -= B[p2]
        p2 += 1

    # print(K, p1, p2)

if K < 0:
    books -= 1
print(books)

Submission status: Runtime Error

Solution code:
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    sA = 0
    AA = []
    for a in A:
        sA += a
        if sA > K:
            break
        AA.append(sA)

    sB = 0
    BB = []
    for b in B:
        sB += b
        if sB > K:
            break
        BB.append(sB)

    AA = AA[::-1]

    M = max(len(AA), len(BB))

    for i in range(len(AA)):
        for j in range(len(BB)):
            if AA[i] + BB[i] <= K:
                m = len(AA) - i + j + 1
                if m > M:
                    M = m
    print(M)

main()

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split())

a = list(map(int, input().split()))
b = list(map(int, input().split()))

time = 0
count = 0
for _ in range(n + m):
    if len(a) > 0and len(b)>0:
        if a[-1] < b[-1]:
            time += a[-1]
            a = a[:-1]
        else:
            time += b[-i-1]
            b = b[:-1]
    elif len(a) == 0 and len(b) > 0:
        time += b[-1]
        b = b[:-1]
    elif len(b) == 0 and len(a) > 0:
        time += a[-1]
        a = a[:-1]
    if time > k:
        break
    else:
        count += 1
        
        
print(count)

Submission status: Runtime Error

Solution code:
import heapq
n,m,k=map(int,input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
time=0
ans=0
if sum(a)+sum(b)<=k:
    print(n+m)
    exit()
heapq.heapify(a)
heapq.heapify(b)
a0=heapq.heappop(a)
b0=heapq.heappop(b)
while True:
  if a0>=b0:
    time+=b0
    if time>k:
      print(ans)
      exit()
    else:
      ans+=1
      b0=heapq.heappop(b)
  else:
    time+=a0
    if time>k:
      print(ans)
      exit()
    else:
      ans+=1
      a0=heapq.heappop(a)

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
result = 0
count = 0
while True:
  if not a and not b:
    print(count)
  if result > k:
    print(count-1)
    break
  if not a:
    result += b.pop()
    count += 1
  elif not b:
    result += a.pop()
    count += 1
  elif a[0] < b[0]:
    result += a.pop(0)
    count += 1
  else:
    result += b.pop(0)
    count += 1

Submission status: Runtime Error

Solution code:
m,n,k =map(int,input().split())
ml=[int(input()) for i in range(m)]
nl=[int(input()) for i in range(N)]
tl=ml+nl
tl.sort()
sum=0
count=0
for i in range(len(t1)):
  if sum+t[i]<k:
    sum=sum+t[i]
    count+=1
print(count)

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
at,bt=0,0
p=0
while p<k:
    if (n!=at and a[at]<b[bt]) or m==bt:
        p+=a[at]
        at+=1
    else:
        p+=b[bt]
        bt+=1
    if n==at and m==bt:
        print(at+bt)
        break
    #print(p)
else:
    print(at+bt-1)

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split())
arA = list(map(int, input().split()))
arB = list(map(int, input().split()))

idxA = idxB = 0
readTime :int = 0
readBooks :int = 0
while readTime < k:
    if arA[idxA] <= arA[idxB] and idxA < n:
        readTime += arA[idxA]
        idxA += 1
    else:
        readTime += arB[idxB]
        idxB += 1
    readBooks += 1
    if idxA >= n and idxB >= m:
        break

print(readBooks)

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint


def ceil(a, b): return (a + b - 1) // b


inf = float('inf')
mod = 10 ** 9 + 7


def pprint(*A):
    for a in A:     print(*a, sep='\n')


def INT_(n): return int(n) - 1


def MI(): return map(int, input().split())


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [I() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    N, M, K = MI()
    A = LI()
    B = LI()
    ans = 0
    total = 0
    for a in A:
        if a + total <= K:
            ans += 1
            total += a
        else:
            break
    for i in range(len(B)):
        total += B[i]
        if total <= K:
            ans += 1
        else:
            total -= A[N-i-1]
            if total <= K:
                continue
            else:
                break
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
time = 0
i = 0
j = 0
while i <= n and j <= m and time <= k:
    if i == n:
        if j == m:
            break
        time += b[j]
        j += 1
        continue
    if j == n:
        time += a[i]
        i += 1
        continue
    if a[i] < b[j]:
        time += a[i]
        i += 1
        continue
    else:
        time += b[j]
        j += 1
        continue
if time > k:
    print(i+j-1)
else:
    print(i+j)

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=0
B=0
ans=0
t=0
for i in range(n+m+1):
    if a[A]>b[B]:
        t+=b[B]
        if k<t:
            break
        else:
            B+=1
            ans+=1
    else:
        t+=a[A]
         if k<t:
            break
        else:
            A+=1
            ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque
def LI():
  return list(map(int,input().split()))

N,M,K = map(int,input().split())
A = deque(LI())
B = deque(LI())
res = 0

while K > 0:
  if len(A) == 0:
    if K >= B[0]:
      b = B.popleft()
      K -= b
    else:
      break
  elif len(B) == 0:
    if K>=A[0]:
      a = A.popleft()
      K -= a
    else:
      break
  else:
    if A[0] > B[0]:
      b = B.popleft()
      K -= b
    elif A[0] < B[0]:
      a = A.popleft()
      K -= a
    else:
      if A[1] > B[1]:
        b = B.popleft()
        K -= b
      else:
        a = A.popleft()
        K -= a

  if K >= 0:
    res += 1
  else:
    break


print(res)

Submission status: Runtime Error

Solution code:
n,m,k = map(int,input().split())
As = list(map(int,input().split()))
Bs = list(map(int,input().split()))

cnt = 0
while True:
    out = 0 
    if As == []:
        if Bs == []:
            break
        else:
            out = Bs[0]
            Bs = Bs[1:]
    elif As[0] > Bs[0]:
        out = Bs[0]
        Bs = Bs[1:]
    else:
        out = As[0]
        As = As[1:]
    k -= out
    if k < 0:
        break
    cnt += 1

print(cnt)

Submission status: Runtime Error

Solution code:
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################

n , m , k = map(int , input().split())
a = list(map(int , input().split()))
b = list(map(int , input().split()))
i = 0
j = 0
ans = 0
while k:
	#print(k,i,j,ans)
	f = 1
	if i < n and a[i] < b[j]:
		if k - a[i] >= 0:
			k-=a[i]
			ans+=1
			i+=1
			f = 0
			if i == n: i = n-1
	elif j < m and b[j] < a[i]:
		if k - b[j] >= 0:
			k-=b[j]
			ans+=1
			j+=1
			f = 0
	if f: break
	if i >= n  and j >= m: break
print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque
n,m,k = map(int,input().split())
a = deque(map(int,input().split()))
b = deque(map(int,input().split()))
cnt = 0
ans = 0
for i in range(n+m):
    if len(a) == 0 or a[0] >= b[0]:
        cnt += b[0]
        b.popleft()
        if cnt > k:
            break
    elif len(b) == 0 or a[0] < b[0]:
        cnt += a[0]
        a.popleft()
        if cnt > k:
            break
    ans += 1
    print(a)
    print(b)
print(ans)

Submission status: Runtime Error

Solution code:
M,N,K = map(int,input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
m = 0
c = 0
while True:
    if len(A) == 0:
        r = B.pop(0)
    elif len(B) == 0:
        r = A.Pop(0)
    elif A[0] > B[0]:
        r = B.pop(0)
    else:
        r = A.pop(0)
    if m+r > K:
        break
    c += 1
    m += r
    if m+r >= K:
        break
print(c)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

n, m, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ans = 0

while k > 0:
    
    cost = 0
    if a[0] > b[0]:
        cost = b[0]
        b.pop(0)
    else:
        cost = a[0]
        a.pop(0)
    
    k -= cost
    if k <= 0:
        break
    else:
        ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
N,M,K = map(int, input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

Acount = 0
Bcount = 0
Time = 0
score = 0
while True:
    if Acount == len(A):
        if Bcount == len(B):
            break
        else:
            Time = Time + B[Bcount]
            Bcount = Bcount + 1
    elif Bcount == len(A):
        if Acount == len(A):
            break
        else:
            Time = Time + A[Acount]
            Acount = Acount + 1
    else:
        if A[Acount] <= B[Bcount]:
            Time = Time + A[Acount]
            Acount = Acount + 1
        else:
            Time = Time + B[Bcount]
            Bcount = Bcount + 1
    
    if Time <= K:
        score = score + 1
    else:
        break
    
print(score)

Submission status: Runtime Error

Solution code:
n, m, k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

cnt = 0
while k > 0:
    if a == []:
        a = [1001001001]
    if b == []:
        a = [1001001001]
    if a[0] < b[0]:
        if k - a[0] < 0:
            print(cnt)
            exit()
        k -= a[0]
        cnt += 1
        a.remove(a[0])
    else:
        if k - b[0] < 0:
            print(cnt)
            exit()
        k -= b[0]
        cnt += 1
        b.remove(b[0])

print(cnt)

Submission status: Runtime Error

Solution code:
n, m , k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

total = 0
res = 0
i_a = 0
i_b = 0
while total < k:
  if i_a >= n:
    total += b[i_b]
    i_b +=1
  elif i_b >= n:
    total += a[i_a]
    i_a += 1
  else:
    if a[i_a] < b[i_b]:
      total += a[i_a]
      i_a += 1
    else:
      total += b[i_b]
      i_b += 1
  if total <= k:
    res += 1
print(res)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

#define LL long long
//#define LL __int64
typedef pair<int, int> pii;
typedef pair<LL, LL> pLL;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;

template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;

    x = 0;
    _f = 0;
    _c = getchar();

    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}
template < typename T, typename ...Args > inline void read(T &x, Args &...args) {read(x); read(args...);}

template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define mt make_tuple
#define pb push_back
#define epb emplace_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

const int INF = 0x3f3f3f3f;
const LL LINF = 0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int e5 = 100000; // 1e5
const int e6 = 1000000; //1e6;
//const int MOD = 1000000007; //1e9 + 7
const int MOD = 998244353;
//const int MOD = 911451407;

template< typename T0, typename T1 > inline void depair(T0 &x, T1 &y, pair<T0, T1> &p) {x = p.fi, y = p.se;}
inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL mod = MOD)
{
    if(n < 0) a = fp(a, mod - 2, mod), n = -n;
    LL res = 1; for(; n; n >>= 1, a = a * a % mod) if(n & 1) res = res * a % mod; return res;
}

struct Mint
{
    int x;
    Mint():x(0) {}
    Mint(int _x): x(_x)
    {
        if(x < 0 || x >= MOD) x %= MOD;
        if(x < 0) x += MOD;
    }
    Mint(LL _x)
    {
        if(_x < 0 || _x >= MOD) _x %= MOD;
        if(_x < 0) _x += MOD;
        x = _x;
    }
    Mint operator - () const{
        return Mint(MOD - x);
    }
    Mint operator + (const Mint &rhs) const{
        return Mint(x + rhs.x >= MOD ? x - MOD + rhs.x : x + rhs.x);
    }
    Mint operator - (const Mint &rhs) const{
        return Mint(x - rhs.x < 0 ? x - rhs.x + MOD : x - rhs.x);
    }
    Mint operator * (const Mint &rhs) const{
        return Mint((LL)x * rhs.x % MOD);
    }
    Mint operator / (const Mint &rhs) const{
        return Mint((LL)x * fp(rhs.x, -1) % MOD);
    }
    Mint& operator += (const Mint &rhs) {
        x += rhs.x; if(x >= MOD) x -= MOD; return *this;
    }
    Mint& operator -= (const Mint &rhs) {
        x -= rhs.x; if(x < 0) x += MOD; return *this;
    }
    Mint& operator *= (const Mint &rhs) {
        x = ((LL)x * rhs.x) % MOD; return *this;
    }
    Mint& operator /= (const Mint &rhs) {
        x = (LL)x * fp(rhs.x, -1) % MOD; return *this;
    }
    bool operator == (const Mint &rhs) const{
        return x == rhs.x;
    }
    bool operator != (const Mint &rhs) const{
        return x != rhs.x;
    }
    friend ostream& operator << (ostream &out, const Mint &rhs){
        return out << rhs.x;
    }
    friend istream& operator >> (istream &in, Mint &rhs){
        return in >> rhs.x;
    }

    Mint inv() {return Mint(fp(x, -1));}
    Mint pow(int k) {return Mint(fp(x, k));}
    Mint pow(const Mint &t) {return Mint(fp(x, t.x));}
};


const int maxn = (int) 1e6 + 20;
const int maxm = (int) 2e6 + 20;

void work()
{
    int n, m;
    LL k;
    cin >>n >>m >>k;

    vector<int> a(n), b(m);
    for(int i = 0; i < n; i++) cin >>a[i];
    for(int i = 0; i < m; i++) cin >>b[i];

    sort(all(a));
    sort(all(b));

    int cnt = 0;

    int j = 0;
    LL jt = 0;
    while(j < m && jt + b[j] <= k) jt += b[j++];

    cnt = j;
    for(int i = 0; i < n; i++)
    {
        k -= a[i];
        if(k < 0) break;
        while(j && jt > k) jt -= b[--j];
        cnt = max(cnt, j + i + 1);
    }
    cout <<cnt <<endl;
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416

    int tc = 1;
//    read(tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
a.reverse()
b.reverse()
ans=0
t=0
while len(a)>0 or len(b)>0:
  if len(a)>0 and a[-1]<b[-1]:
    t+=a.pop()
  elif len(b)>0:
    t+=b.pop()
  if t>k:
    break
  else:
    ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
n,m,k = map(int, input().split())

A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

ans = 0
ai = 0
bi = 0
t = 0
while t < k and (ai < len(A) or bi < len(B)):
  if ai < len(A) and bi < len(B):
    a = A[ai]
    b = B[bi]
    if a < b:
      ai += 1
      t += a
      if t =< k:
        ans += 1
    else:
      bi += 1
      t += b
      if t =< k:
        ans += 1
  elif ai < len(A):
    ai += 1
    t += A[ai]
    if t =< k:
      ans += 1
  else:
    bi += 1
    t += B[bi]
    if t =< k:
      ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n, m, k = ns()
    a = na()
    b = na()

    a_idx = 0
    b_idx = 0
    ans = 0
    cnt = 0
    while True:
        if a_idx == n and b_idx == m:
            break

        if a_idx != n:
            if a[a_idx] < b[b_idx]:
                if ans + a[a_idx] > k:
                    break
                else:
                    ans += a[a_idx]
                    a_idx += 1
                    cnt += 1
            else:
                if ans + b[b_idx] > k:
                    break
                else:
                    ans += b[b_idx]
                    b_idx += 1
                    cnt += 1
        else:
            if ans + b[b_idx] > k:
                break
            else:
                ans += b[b_idx]
                b_idx += 1
                cnt += 1

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import deque
n,m,k=map(int,input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a = deque(a)
b = deque(b)
ans = 0
while(n!=m):
    if(n>m):
        b.append(10**9+1)
        m += 1
    else:
        a.append(10**9+1)
        n +=1
while(k>0):
    if(a[0]>b[0]):
        if(k >= b[0]): 
            k -= b.popleft()
            ans +=1
        else:
            break
    else:
        if(k >= a[0]):
            k -= a.popleft()
            ans += 1
        else:
            break
print(ans)

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = -1
while k > 0:
  if a[0] < b[0]:
    k -= a[0]
    ans += 1
    del a[0]
  else:
    k -= b[0]
    ans += 1
    del b[0]
print(ans)

Submission status: Runtime Error

Solution code:
M,N,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

res = 0
time = 0

while time <= K:
    if A[0] <= B[0]:
        time = time + A.pop(0)
    else:
        time = time + B.pop(0)
    res += 1

print(res)

Submission status: Runtime Error

Solution code:
#!python3.8
# -*- coding: utf-8 -*-
# abc172/abc172_c
import sys
from collections import deque

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, M, K = i2nn()
    A = deque(i2nn())
    B = deque(i2nn())
    t = 0
    n = 0
    while (A and t + A[0] <= K) or (B and t + B[0] <= K):
        n += 1
        t += A.popleft() if A and (A[0] < B[0]) else B.popleft()
    print(n)
    return

main()

Submission status: Runtime Error

Solution code:
n,m,k=map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
a=0
b=0
cnt=0
for i in range(max(n+1,m+1)):
	if min(A[a],B[b])>k:
		break
	if A[a]>=B[b]:
		k-=B[b]
		b+=1
		cnt+=1
	else:
		k-=A[a]
		a+=1
		cnt+=1
print(cnt)

Submission status: Runtime Error

Solution code:
n, m, k =map(int, input().split())
a = [int(x) for x  in input().split()]
b = [int(x) for x in input().split()]
i,j=0,0
cnt = 0
while k>=0 and i<n and j<n:
    if a[i]<b[j]:
        if k>=a[i]:
            k-=a[i]
            #print(k, a[i])
            i+=1
            cnt +=1

        else:
            break
    else:
        if k>=b[j]:
            k-=b[j]
            #rint(k, b[j])
            cnt +=1
            j+=1
        else:
            break

while k>=0 and i<n:
    if k >= a[i]:
        k -= a[i]
        #print(k, a[i])
        cnt += 1
    else:
        break

while k>=0 and j<m:
    if k >= b[j]:
        k -= b[j]
        #print(k, b[j])
        cnt += 1
        j += 1
    else:
        #print(k,b[j])
        break
print(cnt)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))

C = A+B

ans = 0
count = 0
a = 0
b = 0
while ans <= K:
  if A[a] >= B[b]:
    ans += B[b]
    if ans <= K:
      b += 1
    else:
      break
  else:
    ans += A[a]
    if ans <= K:
      a += 1
    else:
      break

print(a+b)

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

p, q = 0, 0
ans = 0
key = 0
while key <= k:
  if p == n and q == m:
    break
  elif p == n:
    if key+b[q] <= k:
      ans += 1
      key += b[q]
      q += 1
    else:
      break
  elif q == m:
    if key+a[p] <= k:
      ans += 1
      key += a[p]
      p += 1
    else:
      break
  else:
    if a[p] < b[q]:
      if key+a[p] <= k:
        ans += 1
        key += a[p]
        p += 1
      else:
        break
    elif a[p] > b[q]:
      if key+b[q] <= k:
        ans += 1
        key += b[q]
        q += 1
      else:
        break
    else:
      if a[p] + key > k:
        break
      if a[p+1] <= b[q+1]:
        ans += 1
        key += a[p]
        p += 1
      else:
        ans += 1
        key += b[q]
        q += 1

print(ans)

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a = 0
b = 0
ans = 0
if sum(A) + sum(B) <= K:
    print(N+M)
    exit()
while min(A[a],B[b]) <= K:
    if a == N:
        K -= B[b]
        b += 1
    elif b == M:
        K -= A[a]
        a += 1
    elif A[a] == min(A[a],B[b]):
        K -= A[a]
        a += 1
    else:
        K -= B[b]
        b += 1
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

n,m,k = map(int,stdin.readline().rstrip().split())
a = list(map(int,stdin.readline().rstrip().split()))
b = list(map(int,stdin.readline().rstrip().split()))

nowa = 0
nowb = 0

li = []
total = 0

while total <= k:
    if nowa == n and nowb == m:
        break
    if nowa == n and nowb < m:
        total += b[nowb]
        li.append(b[nowb])
        nowb += 1
    elif nowa < n and nowb == m:
        total += b[nowb]
        li.append(b[nowb])
        nowa += 1  
    elif a[nowa] <= b[nowb]:
        total += a[nowa]
        li.append(a[nowa])
        nowa += 1
    elif a[nowa] > b[nowb]:
        total += b[nowb]
        li.append(b[nowb])
        nowb += 1

if sum(li) <= k:
    print(len(li))
else:
    print(len(li)-1)

Submission status: Runtime Error

Solution code:
N,M,K=map(int,input().split())
A = list(map(int, input().split())) 
B = list(map(int, input().split())) 
ans1=0
ans2=0
i=0
j=0
while i>=0:
    ans1+=A[i]
    if ans1>K:
        ans1=ans1-A[i]
        break
    i=+1
while j>=0:
    ans2+=B[j]
    if ans2>K:
        ans2=ans2-B[j]
        break
    j+=1
print(i+j)

Submission status: Runtime Error

Solution code:
import numpy as np
#from numba import njit

#(N, K) = map(int, input().split())
#A = np.array(list(map(int, input().split())))
(N,M,K) = map(int, input().split())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))

#@njit

count = 0
t = min(A[0],B[0]) <= K
while (t):
    if (A[0] < B[0]):
        K -= A[0]
        A = A[1:]
    else:
        K -= B[0]
        B = B[1:]
    count += 1
    if ((len(A),len(B)) == (0,0)):
        t = False
    elif (len(A) == 0):
        t = B[0] <= K
    else:
        t = A[0] <= K

print(count)

Submission status: Runtime Error

Solution code:
N = int(input())

ret = 0
for i in range(1, N + 1) :
  j = N // i
  if j < 1 :
    break
  ret += (1 + j) * i * j // 2
  
print(ret)

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split())

a = list(map(int, input().split()))
b = list(map(int, input().split()))

time = 0
count = 0
for _ in range(n * m):
    if len(a) > 0and len(b)>0:
        if a[-1] < b[-1]:
            time += a[-1]
            a = a[:-1]
        else:
            time += b[-i-1]
            b = b[:-1]
    elif len(a) == 0:
        time += b[-1]
        b = b[:-1]
    elif len(b) == 0:
        time += a[-1]
        a = a[:-1]
    if time > k:
        print(count)
        break
    else:
        count += 1

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

cntA = 0
cntB = 0
time = 0
ans = 0
while time <= K:
    if ans >= N+M:
        break
    if (cntB == M-1) or (cntA <= N-1 and A[cntA] <= B[cntB]):
        time += A[cntA]
        cntA += 1
    else:
        time += B[cntB]
        cntB += 1
    if time <= K:
        ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
from bisect import *
from itertools import accumulate
n, m, k = map(int, input().split())
a = [0]+list(map(int, input().split()))
b = [0]+list(map(int, input().split()))
a = accumulate(a)
b = accumulate(b)
ans = 0
for i in range(n+1):
    ind = bisect_right(b, k-a[i])
    ans = max(ans, ind+i-1)

print(ans)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

pa, pb = 0, 0

ans = 0
while 1:
  if A[pa] < B[pb]:
    if K - A[pa] >= 0:
      ans += 1
      pa += 1
    else:
      break
  else:
    if K - B[pb] >= 0:
      ans += 1
      pb += 1
    else:
      break

Submission status: Runtime Error

Solution code:
import sys

def read_int():
    l = sys.stdin.readline().rstrip('\n').split(' ')
    return int(l[0])

def read_int_list():
    l = sys.stdin.readline().rstrip('\n').split(' ')                                                  
    return [int(i) for i in l]

N, M, K = tuple(read_int_list())                                                                      
A = read_int_list()                                                                                   
B = read_int_list()                                                                                   

def can_read(A, B, i, j, memo, k):                                                                    
    key = (i, j, k)                                                                                   
    if key in memo:                                                                                   
        return memo[key]                                                                              
    ans = 0
    if i < len(A) and A[i] <= k:                                                                      
        ans = max(ans, can_read(A, B, i+1, j, memo, k - A[i]) + 1)                                    
    if j < len(B) and B[j] <= k:                                                                      
        ans = max(ans, can_read(A, B, i, j+1, memo, k - B[j]) + 1)                                    
    memo[key] = ans                                                                                   
    return ans                                                                                        

memo = {}                                                                                             
print(can_read(A, B, 0, 0, memo, K))