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: Wrong Answer

Solution code:
from collections import deque
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
QA = deque(A)
B = list(map(int,input().split()))
QB = deque(B)
INF = float("inf")
ans = 0
nokori = K*1
while QA or QB:
    if QA:
        ta = QA[0]
    else:
        ta = INF
    if QB:
        tb = QB[0]
    else:
        tb = INF
    if ta <= tb and ta <= nokori:
        ans +=1
        nokori -= ta
        QA.popleft()
    elif tb<= ta and tb <= nokori:
        ans +=1
        nokori -= tb
        QB.popleft()
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
from itertools import accumulate
ar=[0]+list(accumulate(a))
bru=[0]+list(accumulate(b))
from bisect import bisect_left as bl,bisect_right as br
ans=0
print(ar,bru)
for i in range(n+1):
    g=ar[i]
    if g>k:break
    if k-g>=bru[-1]:ans=max(ans,i+m);continue
    j=bl(bru,k-g)
    ans=max(ans,i+j-1)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

ai = 0
bi = 0

sm = 0
ans = 0
while True:
    if ai == N and bi == M:
        break
    if ai != N and bi != M:
        if sm + min(A[ai], B[bi]) > K:
            break
        if A[ai] < B[bi]:
            sm += A[ai]
            ai += 1
        else:
            sm += B[bi]
            bi += 1
    elif ai == N:
        if sm + B[bi] > K:
            break
        sm += B[bi]
        bi += 1
    else:
        if sm + A[ai] > K:
            break
        sm += A[ai]
        ai += 1
    ans += 1
print(ans)

Submission status: Wrong Answer

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

sum = 0
book = 0
while (True):
    if (len(Alist) == 0):
        Alist.append(10000000000)
    elif(len(Blist) == 0):
        Blist.append(10000000000)

    if (Alist[0] < Blist[0]):
        if (sum + Alist[0] <= k):
            sum += Alist[0]
            Alist.pop(0)
            book += 1
        else:
            break
    else:
        if (sum + Blist[0] <= k):
            sum += Blist[0]
            Blist.pop(0)
            book += 1
        else:
            break

print(book)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
A_top = A[0]
B_top = B[0]
a_idx = 1
b_idx = 1
while K:
    if A_top == B_top == float('inf'):
        break
    if A_top > B_top:
        if K < B_top:
            break
        K -= B_top
        ans += 1
        if b_idx < M:
            B_top = B[b_idx]
            b_idx += 1
        else:
            B_top = float('inf')
    else:
        if K < A_top:
            break
        K -= A_top
        if a_idx < N:
            A_top = A[a_idx]
            a_idx += 1
        else:
            a_top = float('inf')
        ans += 1
print(ans)

Submission status: Wrong Answer

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

c.sort()
#print(c)

for i in range(n+m):
    if k - c[i] >= 0:
        k -= c[i]
        ans += 1
    else:
        break
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

i, j = 0, 0
time, books = 0, 0
while True:
    if i < n and j < m:
        if a[i] > b[j]:
            if k - time >= b[j]:
                time += b[j]
                books += 1
                j += 1
            else:
                break
        elif a[i] < b[j]:
            if k - time >= a[i]:
                time += a[i]
                books += 1
                i += 1
            else:
                break
        else:
            if k - time >= a[i]:
                time += a[i]
                time += b[j]
                books += 2
                i += 1
                j += 1
            else:
                break

    elif i < n and j >= m:
        if k - time >= a[i]:
            time += a[i]
            books += 1
            i += 1
        else:
            break

    elif i >= n and j < m:
        if k - time >= b[j]:
            time += b[j]
            books += 1
            j += 1
        else:
            break
    
    else:
        break
    
    if time >= k:
        break

print(books)

Submission status: Wrong Answer

Solution code:
from bisect import*
from itertools import*

N, M, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = list(accumulate(a))
b = list(accumulate(b))
ans = 0
for i in range(N):
    rest = K - a[i]
    if rest < 0:
        continue
    else:
        pre = bisect(b, rest)
        ans = max(ans, i+1+pre)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
INF = 1000000000000

n,m,k = LI()
a = LI()
b = LI()

i=0
j=0
t = 0
while(t <= k):
    if(i == n):
        t += b[j]
        j += 1
    elif(j == m):
        t += a[i]
        i += 1
    else:
        if(a[i] < b[j]):
            t += a[i]
            i += 1
        else:
            t += b[j]
            j += 1
    if(i == n and j == m):
        break

if(t > k):
    print(i + j - 1)
else:
    print(i + j)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
import bisect
n,m,k=map(int,input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]

A=list(accumulate(a))
B=list(accumulate(b))
ans=0
for i in range(len(a)):
    r = (k-A[i])
    if r<=0:
        break
    #print(r,bisect.bisect_left(B,r))
    #print(B[bisect.bisect_left(B,r)])
    ans=max(ans,i+1+bisect.bisect_right(B,r))
print(ans)

Submission status: Wrong Answer

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()))
a = A.popleft()
b = B.popleft()
k = 0
n = 0
while k <= K:
    if a < b:
        if k + a <= K:
            k += a
            a = A.popleft() if len(A) else 10**10
            n += 1
        else:
            break
    else:
        if k + b <= K:
            k += b
            b = B.popleft() if len(B) else 10**10
            n += 1
        else:
            break
print(n)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    N, M, K = [int(x) for x in input().strip().split()]
    A = [int(x) for x in input().strip().split()] + [float('inf')]
    B = [int(x) for x in input().strip().split()] + [float('inf')]
    cumsum = 0
    ans = 0
    ai = 0
    bi = 0
    while cumsum <= K:
        if A[ai] <= B[bi]:
            if cumsum + A[ai] <= K:
                cumsum += A[ai]
                ans += 1
                ai += 1
            else:
                break
        else:
            if cumsum + B[bi] <= K:
                cumsum += B[bi]
                ans += 1
                bi += 1
            else:
                break
            
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

A_sum = [0]*(N+1)
for i in range(N):
    A_sum[i+1] = A[i]+A_sum[i]
B_sum = [0]*(M+1)
for i in range(M):
    B_sum[i+1] = B[i]+B_sum[i]

ans = 0
for i in range(N+1):
    if 0 < K-A_sum[i]:
        j = bisect_right(B_sum,K-A_sum[i])
        ans = max(ans,i+j-1)

print(ans)

Submission status: Wrong Answer

Solution code:

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

readed = 0
ans = 0
while readed <= K:
    if not A and not B:
        break
    read = 0
    if A and B:
        if A[0] < B[0]:
            read += A.pop(0)
        else:
            read += B.pop(0)
    elif A:
        read += A.pop(0)
    elif B:
        read += B.pop(0)
    if readed + read > K:
        break
    readed += read
    ans += 1

print(ans)

Submission status: Wrong Answer

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()]
cnt = 0
t = 0
while(k > t):
    if(len(A)==0):
        now = B.pop(0)
        t += now
        cnt += 1
    elif(len(B)==0):
        now = A.pop(0)
        t += now
        cnt += 1
    else:
        if(A[0] > B[0]):
            now = B.pop(0)
        else:
            now = A.pop(0)
        t += now
        cnt += 1

if(t > k):
    cnt -= 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
i=j=0
cnt=0
if sum(s)+sum(t)<=k:print(n+m)
else:
    while i<n or j<m:
        if cnt>k:break
        if j>=m:cnt+=s[i];i+=1;
        elif i>=n:cnt+=t[j];j+=1
        elif s[i]<t[j]:cnt+=s[i];i+=1;
        else:cnt+=t[j];j+=1
    print(i+j-1)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True


def main():
    N, M, K = MI()
    A = LI()
    B = LI()
    a_idx = 0
    b_idx = 0
    ans = 0

    while K > 0:
        if a_idx < N and b_idx < M:
            if A[a_idx] < B[b_idx] and A[a_idx] <= K:
                K -= A[a_idx]
                a_idx += 1
                ans += 1
            elif B[b_idx] <= K:
                K -= B[b_idx]
                b_idx += 1
                ans += 1
            else:
                break
        elif a_idx >= N and b_idx < M:
            if B[b_idx] <= K:
                K -= B[b_idx]
                b_idx += 1
                ans += 1
            else:
                break
        elif a_idx < N and b_idx >= M:
            if A[a_idx] <= K:
                K -= A[a_idx]
                a_idx += 1
                ans += 1
        else:
            break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque
n,m,k=map(int,input().split())
A=deque(list(map(int,input().split())))
B=deque(list(map(int,input().split())))

point=0
while k>0:
    if len(A)!=0 and len(B)!=0:
        if A[0]>B[0]:k -=B.popleft()
        else:k -=A.popleft()
    elif len(A)==0:
        k -=B.popleft()
    elif len(B)==0:
        k -=A.popleft()

    if k>=0:point +=1
    else:break
print(point)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

def solve():
    N,M,K = map(int, input().split())
    A = iter(map(int, input().split()))
    B = iter(map(int, input().split()))
    T = 0
    c = 0
    a = next(A)
    b = next(B)
    while T < K:
        if a < b:
            T += a
            c += 1
            try:
                a = next(A)
            except:
                a = float('inf')
        elif b < float('inf'):
            T += b
            c += 1
            try:
                b = next(B)
            except:
                b = float('inf')
        else:
            break
    if T > K:
        c -= 1
    return str(c)

if __name__ == '__main__':
    print(solve())

Submission status: Wrong Answer

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

li = lin + lim
li.sort()

t = 0
ans = 0

for i in li:
    t += i
    if t>k:
        print(ans)
        break
    elif t==k:
        print(ans+1)
        break
    else:
        ans+=1

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=[int(x) for x in input().split()]
B=[int(y) for y in input().split()]
A.append(10**9+1)
B.append(10**9+1)
ans=0
a_index=0
b_index=0
time=K
while(1):
    if A[a_index]<B[b_index]:
        if time<A[a_index]:
            break
        else:
            ans+=1
            time-=A[a_index]
            a_index+=1
    else:
        if time<B[b_index]:
            break
        else:
            ans+=1
            time-=B[b_index]
            b_index+=1
print(ans)

Submission status: Wrong Answer

Solution code:
"""
    こんにちは。これはクシャルです
    
    Author : thekushalghosh (クシャル)
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time
start_time = time.time()
##########################################################################
################# ---- THE ACTUAL CODE STARTS BELOW ---- #################

def solve():
    n,m,k = invr()
    a = list(reversed(inlt()))
    b = list(reversed(inlt()))
    c = 0
    while k > 0:
        if a and b:
            if a[-1] < b[-1] and k - a[-1] >= 0:
                k = k - a.pop()
                c = c + 1
            elif a[-1] >= b[-1] and k - b[-1] >= 0:
                k = k - b.pop()
                c = c + 1
            else:
                break
        elif a and k - a[-1] >= 0:
            k = k - a.pop()
            c = c + 1
        elif b and k - b[-1] >= 0:
            k = k - b.pop()
            c = c + 1
        else:
            break
    print(c)
            
################## ---- THE ACTUAL CODE ENDS ABOVE ---- ##################
##########################################################################
 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
        sys.stdout.close()
    
#---------------------- USER DEFINED INPUT FUNCTIONS ----------------------#
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))
 
#------------------ USER DEFINED PROGRAMMING FUNCTIONS ------------------#
def counter(a):
    q = [0] * max(a)
    for i in range(len(a)):
        q[a[i] - 1] = q[a[i] - 1],1
    return(q)
 
def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97],1
    return(q)

def factors(n):
    q = []
    for i in range(1,int(n ** 0.5) + 1):
        if n % i == 0: q.append(i); q.append(n // i)
    return(list(sorted(list(set(q)))))

def prime_factors(n):
    q = []
    while n % 2 == 0: q.append(2); n = n // 2
    for i in range(3,int(n ** 0.5) + 1,2):
        while n % i == 0: q.append(i); n = n // i
    if n > 2: q.append(n)
    return(list(sorted(q)))

#-----------------------------------------------------------------------#
        
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
main()

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
AB = A + B
AB.sort()
ans = 0
for ab in AB:
    if K - ab > 0:
        K = K - ab
        ans += 1
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import defaultdict as dd
from collections import deque as dq
import itertools as it
from math import sqrt, log, log2
from fractions import Fraction

# t = int(input())
# for _ in range(t):
n, m, k = map(int, input().split())
a = dq(map(int, stdin.readline().split()))
b = dq(map(int, stdin.readline().split()))
# nums = list(map(int, stdin.readline().split()))

tot = 0
count = 0
while tot <= k:
    if tot == k:
        break

    atop = a[0] if a else 10**10
    btop = b[0] if b else 10**10

    if atop == 10**10 and btop == 10**10:
        break

    if atop < btop:
        if tot + atop <= k:
            tot += a.popleft()
            count += 1
        else:
            break
    else:
        if tot + btop <= k:
            tot += b.popleft()
            count += 1
        else:
            break
print(count)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from itertools import accumulate
N,M,K= map(int,input().split())

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

AB = sorted(A+B)

C = accumulate(AB)

ans = 0
for i,c in enumerate(C):
    if c <= K:
        ans = i+1

print(ans)

Submission status: Wrong Answer

Solution code:
n , m , k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
coua = 0
coub = 0
nokori = k
ans = 0
while True:
    if coua != n and coub != m:
        if a[coua] >= b[coub]:
            nokori -= b[coub]
            coub += 1
        elif a[coua] < b[coub]:
            nokori -= a[coua]
            coua += 1
    elif coua == n and coub != m:
        nokori -= b[coub]
        coub += 1
    elif coua != n and coub == m:
        nokori -= a[coua]
        coua += 1
    elif coua == n and coub ==m:
        break
    
    if nokori >=0:
        ans+=1
    elif nokori <0:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k =map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in a:
  b.append(i)
b = sorted(b)
cnt = 0
m = 0
for i in b:
  m += i
  if m <= k:
    cnt += 1
  else:
    print(cnt)
    exit(0)
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import deque


def main():
    n, m, k = [int(x) for x in input().split()]
    array_a = deque(int(x) for x in input().split())
    array_b = deque(int(x) for x in input().split())
    count = 0
    while k > 0:
        if not (array_a or array_b):
            break
        elif not array_a:
            book = array_b.popleft()
        elif not array_b:
            book = array_a.popleft()
        else:
            if array_a[0] < array_b[0]:
                book = array_a.popleft()
            else:
                book = array_b.popleft()

        if k >= book:
            k -= book
            count += 1
        else:
            break
    print(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

ans = 0
ans0 = 0
ans1 = 0
for i in range(n):
    if A[i] + ans0 <= k:
        ans0 += A[i]
        ans1 += 1
    else:
        break
ind = ans1-1

jnd = 0
for i in range(m):
    if B[i] + ans0 <= k:
        ans0 += B[i]
        ans1 += 1
        jnd += 1
    else:
        break


ans = ans1
# print(ans)

for i in range(ind, -1, -1):
    ans1 -= 1
    ans0 -= ind
    while jnd < m and ans0 + B[jnd] <= k:
        ans0 += B[jnd]
        jnd += 1
        ans1 += 1
    ans = max(ans, ans1)
print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
A.append(K)
B.append(K)
cnt=0
z=K
a,b=0,0
for i in range(N+M+1):
  if min(A[a],B[b])>z:
    print(cnt)
    break
  if A[a]<=B[b]:
    cnt+=1
    z-=A[a]
    a+=1
  else:
    cnt+=1
    z-=B[b]
    b+=1

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
A=[int(i) for i in input().split()]+[10**9]
B=[int(i) for i in input().split()]+[10**9]
a=A.pop(0)
b=B.pop(0)
ans=0
while k>0:
    ans+=1
    k-=min(a,b)
    if a<b:
        a=A.pop(0)
    else:
        b=B.pop(0)
print(ans-1*(k<0))

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,m,k = na()
a = na()
b = na()
aa = 0
bb = 0
tl = 0

for i in range(n+m):
    aaa = a[aa] if aa < n else 100000000000
    bbb = b[bb] if bb < m else 100000000000
    if aaa > bbb:
        tl += b[bb]
        bb+=1
    else:
        tl+=a[aa]
        aa+=1
    if tl > k:
        print(i)
        exit()

print(n+m)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
c_list = a_list + b_list
count = 0
time = 0
c_list.sort()
for i in range(n+m):
  if time + c_list[i] <= k:
    count += 1
    time += c_list[i]
    
print(count)

Submission status: Wrong Answer

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

sum=0
i=0
j=0
while True:
    if (i<len(a))&(j<len(b)):
        if a[i]<=b[j]:
            sum+=a[i]
            if sum>k:
                break
            i+=1
        else:
            sum+=b[j]
            j+=1
            if sum>k:
                break
    elif (i==len(a))&(j!=len(b)):
        sum+=b[j]
        if sum>k:
            break
        j+=1
    elif (i!=len(a))&(j==len(b)):
        sum+=a[i]
        if sum>k:
            break
        i+=1
    else:
        break
print(i+j)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from itertools import accumulate
from bisect import bisect_right
sys.setrecursionlimit(10**8)
INF = float("inf")


def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split())) + [INF]
    B = list(map(int, input().split())) + [INF]
    a = 0
    b = 0
    tot = 0
    while True:
        # print(tot)
        if A[a] < B[b]:
            if tot + A[a] > K:
                break
            tot += A[a]
            a += 1
        else:
            if tot + B[b] > K:
                break
            tot += B[b]
            b += 1
    print(a+b)

    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import bisect
import itertools
n, m, k = list(map(int, input().split()))
al = list(map(int, input().split()))
bl = list(map(int, input().split()))

rui_al = [0] + list(itertools.accumulate(al))
rui_bl = [0] + list(itertools.accumulate(bl))


ans = 0

for i in range(1, n+1):
    sum_a = rui_al[i]
    if sum_a >= k:
        continue
    j = bisect.bisect(rui_bl, k-sum_a)
    ans = max(ans, i+j-1)

print(ans)

Submission status: Wrong Answer

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n,m,k=n1()
A=n1()
B=n1()

s=0
a=0
b=0
while s<=k:
    if a==n and b==m:
        a+=1
        break
    elif a==n:
        s+=B[b]
        b+=1
    elif b==m:
        s+=A[a]
        a+=1
    else:
        if A[a]<=B[b]:
            s+=A[a]
            a+=1
        else:
            s+=B[b]
            b+=1
print(a+b-1)

Submission status: Wrong Answer

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()]
cnt = 0
t = 0
while(k > t):
    if(len(A)==0):
        now = B.pop(0)
        t += now
        cnt += 1
    elif(len(B)==0):
        now = A.pop(0)
        t += now
        cnt += 1
    else:
        if(A[0] > B[0]):
            now = B.pop(0)
        else:
            now = A.pop(0)
        t += now
        cnt += 1
print(t,k)
if(t > k):
    cnt -= 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


def inpl():
    return list(map(int, input().split()))


def main():
    N, M, K = inpl()
    A = inpl()
    B = inpl()
    a, b = 0, 0
    while True:
        if a == len(A) and b == len(B):
            break
        elif a == len(A):
            if B[b] > K:
                break
            else:
                K -= B[b]
                b += 1
        elif b == len(B):
            if A[a] > K:
                break
            else:
                K -= A[a]
                a += 1
        elif A[a] > K and B[b] > K:
            break
        elif A[a] < B[b]:
            K -= A[a]
            a += 1
        elif B[b] < A[a]:
            K -= B[b]
            b += 1

    print(a + b)

    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#import math
#import numpy as np
#import torch
#import torch.nn as nn
#import matplotlib.pyplot as plt
#from decimal import Decimal
#import itertools
#import collections

#N=int(input())
N,M,K = map(int,input().split())
#B,W = map(int,input().split())
#T=int(input())
A = list(map(int,input().split()))
#S=str(input())
B = list(map(int,input().split()))
c=0
while K>0:
    if A and B:
        if A[0]>B[0]:
            b=B.pop(0)
            K-=b
            if K<0:
                print(c)
                exit()
            c+=1
        else:
            a=A.pop(0)
            K-=a
            if K<0:
                print(c)
                exit()
            c+=1
    elif A:
        a=A.pop(0)
        K-=a
        if K<0:
            print(c)
            exit()
        c+=1
    elif B:
        b=B.pop(0)
        K-=b
        if K<0:
            print(c)
            exit()
        c+=1
    else:
        print(c)
        exit()
print(c)

Submission status: Wrong Answer

Solution code:
def resolve():
    from collections import deque
    n,m,k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    a = deque(a)
    b = deque(b)
    min = 0
    ans = 0
    for i in range(n+m):
        if a and b:
            ab = a.popleft()
            bb = b.popleft()
            if ab <= bb:
                b.appendleft(bb)
                read = ab
            else:
                a.appendleft(ab)
                read = bb
            if min + read <= k:
                min += read
                ans += 1
            else:
                break
        elif len(a) == 0 and len(b) == 0:
            break
        elif len(a) == 0:
            bb = b.popleft()
            read = bb
            if min + read <= k:
                min += read
                ans += 1
            else:
                break
        elif len(b) == 0:
            ab = a.popleft()
            read = ab
            if min + read <= k:
                min += read
                ans += 1
            else:
                break
    print(ans)
resolve()

Submission status: Wrong Answer

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

alist.reverse()
blist.reverse()

answer=0
while True:
  if alist and blist:
    next=min(alist[-1],blist[-1])    
    if K-next<0:
      break
      
    if alist[-1]<=blist[-1]:
      K-=alist[-1]
      alist.pop()
    else:
      K-=blist[-1]
      blist.pop()
    answer+=1
  elif alist:
    next=alist[-1]
    if K-next<0:
      break
      
    K-=alist[-1]
    alist.pop()
    answer+=1
  elif blist:
    next=blist[-1]
    if K-next<0:
      break
      
    K-=blist[-1]
    blist.pop()
    answer+=1
  else:
    break

print(answer)

Submission status: Wrong Answer

Solution code:
N,M,K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.append(10**9+7)
B.append(10**9+7)
ans = 0

while True:
    if A[0] >= B[0]:
        K = K- B[0]
        B = B[1:]
        ans +=1
    else:
        K = K-A[0]
        A = A[1:]
        ans +=1
    if K <0:
        break
print(ans-1)