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:
input_data = [input().split() for l in range(3)]

limit = int(input_data[0][2])
deskA = [int(m) for m in input_data[1]]
deskB = [int(m) for m in input_data[2]]
num = 0

while True:
  try:
    if not deskA:
      limit -= int(deskB.pop(0))
    elif not deskB:
      limit -= int(deskA.pop(0))
    elif deskA[0] >= deskB[0]:
      limit -= int(deskB.pop(0))
    else:
      limit -= int(deskA.pop(0))
    if limit < 0:
      break
    num += 1

  except IndexError:
    break

print(num)

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_time = 0
L = []
a, b = 0, 0
while sum(L) < K:
    if (len(A) - 1 < a and len(B) - 1 < b):
        print(len(L))
        exit()
    if (len(A) - 1 < a and len(B) - 1 >= b):
        L.append(B[b])
        b += 1
        continue
    elif (len(A) - 1 >= a and len(B) - 1 < b):
        L.append(A[a])
        a += 1
        continue

    if (A[a] <= B[b]):
        L.append(A[a])
        a += 1
    else:
        L.append(B[b])
        b += 1

if (sum(L) == K):
    print(len(L))
    exit()
elif(sum(L) > K):
    print(len(L) - 1)
    exit()

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()))

cumsum=0
cnt=0
i=0
j=0
while True:
    if i>n-1:
        a_i=10**9 + 1
    else:
        a_i=a[i]

    if j>m-1:
        b_i=10**9 + 1
    else: 
        b_i=b[j]   

    if a_i<=b_i:
        cumsum+=a_i
        i+=1
    else:
        cumsum+=b_i
        j+=1

    if cumsum<=k:   
        cnt+=1
    else:
        break

    #本をすべてとった
    if i>n-1 and j>m-1:
        cnt=n+m
        break
    
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import deque
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    i, j = 0, 0
    while K > 0:
        if i == N:
            if j != M:
                read = B[j]
                if K >= read:
                    K -= read
                    j += 1
                else:
                    i -= 1
                    break
            else:
                i = N
                j = M
                break

        elif j == M:
            if i != N:
                read = A[i]
                if K >= read:
                    K -= read
                    i += 1
                else:
                    j -= 1
                    break
            else:
                i = N
                j = M
                break
        else:
            if A[i] >= B[j]:
                read = B[j]
                if K >= read:
                    K -= read
                    j += 1
                else:
                    break
            else:
                read = A[i]
                if K >= read:
                    K -= read
                    i += 1
                else:
                    break
    print(i+j)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    a.append(10**9)
    b.append(10**9)
    a, b = a[::-1], b[::-1]
    sum = 0
    for _ in range(400001):
        if a[-1] <= b[-1]:
            k -= a.pop()
        else:
            k -= b.pop()

        if k < 0:
            break
        sum += 1
    print(sum)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

import itertools


def main():
    n, m, k = map(int, input().split())
    a_list = list(map(int, input().split()))
    b_list = list(map(int, input().split()))

    a_sum = b_sum = 0
    a_i = b_i = 0
    while a_i < len(a_list) and a_sum + a_list[a_i] <= k:
        a_sum += a_list[a_i]
        a_i += 1
    ans = a_i

    while a_i > 0:
        a_sum -= a_list[a_i - 1]
        while b_i < len(b_list) and a_sum + b_sum + b_list[b_i] <= k:
            b_sum += b_list[b_i]
            b_i += 1
            ans = max(ans, a_i + b_i)
        a_i -= 1

    print(ans)


if __name__ == '__main__':
    main()

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(" ")))

total = 0
while total < k and (alist != [] or blist != []):
  if alist == []:
    total += blist[0]
    blist.pop(0)
  elif blist == []:
    total += alist[0]
    alist.pop(0) 
  elif alist[0] <= blist[0]:
    total += alist[0]
    alist.pop(0)
  elif alist[0] > blist[0]:
    total += blist[0]
    blist.pop(0)
if total < k:
  print(m+n)
elif total == k:
  print(m+n-len(alist)-len(blist))
else:
  print(m+n-len(alist)-len(blist)-1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# import bisect
# from collections import Counter, deque, OrderedDict, defaultdict
# from copy import copy, deepcopy # pythonのみ．copyは1次元，deepcopyは多次元．
# from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    n,m,k=map(int,input().split())
    A=[0]+list(map(int,input().split()))
    B=[0]+list(map(int,input().split()))

    from itertools import accumulate
    
    
    AA = [0] + A
    BB=[0]+B
    # 累積和を格納したリスト．A[l:r]の総和はB[r] - B[l]
    AA = list(accumulate(A))
    BB=list(accumulate(B))

    ans=0
    for i in range(1,n+1):
    
        for j in range(1,m+1):
            if AA[i]+BB[j]<=k:
                ans=max(ans,i+j)
    print(ans)

    
resolve()

Submission status: Wrong Answer

Solution code:
import sys
import os
import itertools
import numpy as np
from collections import deque

def main():
    if os.getenv("ENV")=='LOCAL':
        sys.stdin = open(os.path.dirname(__file__)+'/input.txt', 'r')

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

    lA=len(A)-1
    Ap=0
    Bp=0
    n=0
    t=0

    for i in range(len(A)): #Aは可能な限り足す
        if t+A[i]>K:
            break
        Ap=i
        t+=A[i]
        n+=1
    for i in range(len(B)):
        if t+B[i]>K:
            break
        Bp=i
        t+=B[i]
        n+=1

    max=n #読める本の最大値

    for i in range(len(A)):
        n-=1
        t-=A[lA-i]
        for i in range(Bp,len(B)):
            if t+B[i]>K:
                break
            Bp=i
            t+=B[i]
            n+=1
        if max<n:
            max=n

    print(n)

if __name__ == '__main__':
    main()

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()))

maxrnum = 0
sum1 = 0
for n in range(N):
    sum1 += A[n]
    sum2 = 0
    for m in range(M):
        sum2 += B[m]
        rtime = sum1 + sum2
        if rtime<=K:
            rnum = n+1+m+1
            if rnum>maxrnum:
                maxrnum = rnum

print(maxrnum)

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.reverse()
b.reverse()
while True:
    if len(a) == 0 and len(b) == 0:
        break
    if len(a) == 0:
        k -= b.pop()
    elif len(b) == 0:
        k -= a.pop()
    else:
        if a[-1] < b[-1]:
            k -= a.pop()
        else:
            k -= b.pop()
    if k < 0:
        break
    ans += 1

print(ans)

Submission status: Wrong Answer

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

N, M, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

books = []
ai, bi = 0, 0

while sum(books) <= K:
    if ai == N:
        if bi == M:
            break
        else:
            books.append(B[bi])
            bi += 1
    elif bi == M:
        books.append(A[ai])
        ai += 1
    elif A[ai] <= B[bi]:
        books.append(A[ai])
        ai += 1
    else:
        books.append(B[bi])
        bi += 1

if sum(books) > K:
    del books[-1]

print(len(books))

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
t = 0
ans = 0
while t < k:
  if len(a) > 0 and len(b) > 0:
    if a[0] <= b[0]:
      if t + a[0] < k:
        t += a[0]
        a.pop(0)
        ans += 1
      else:
        break
    else:
      if t + b[0] < k:
        t += b[0]
        b.pop(0)
        ans += 1
      else:
        break
  elif len(a) > 0 and len(b) == 0:
    if t + a[0] < k:
      t += a[0]
      a.pop(0)
      ans += 1
    else:
      break
  elif len(a) == 0 and len(b) > 0:
    if t + b[0] < k:
      t += b[0]
      b.pop(0)
      ans += 1
    else:
      break
  elif len(a) == 0 and len(b) == 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()))
A.append(10**10)
B.append(10**10)

ans = 0
for i in range(N+M):
  if A[0] >= B[0]:
    ans += B[0]
    B.pop(0)
  else:
    ans += A[0]
    A.pop(0)
  if ans > K:
    print(i)
    break
    
if ans <= K:
  print(N+M)

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()))
MAX = 10 ** 9 +1
A.append(MAX)
B.append(MAX)
a, b, time = 0, 0, 0
for i in range(0,len(A)+len(B)):
    if A[a] < B[b]:
        time += A[a]
        a += 1
    else:
        time += B[b]
        b += 1
    if time > K:
        break
print(i)

Submission status: Wrong Answer

Solution code:
from collections import deque
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ad = deque(a)
ad.append(float('inf'))
bd = deque(b)
bd.append(float('inf'))
count = 0
while True:
    if k <= 0:
        if k == 0:
            count += 1
        break
    k = k - min(ad[0],bd[0])
    if ad[0] > bd[0]:
        bd.popleft()
    else:
        ad.popleft()
    count += 1
print(count-1)

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(2*10**9)
B.append(2*10**9)

ans = 0
t = 0
ia, ib = 0, 0
while t <= K and (ia < N or ib < M):
    if A[ia] <= B[ib]:
        if t + A[ia] <= K:
            t += A[ia]
            ans += 1
            ia += 1
        else: break
    else:
        if t + B[ib] <= K:
            t += B[ib]
            ans += 1
            ib += 1
        else: break

print(ans)

Submission status: Wrong Answer

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

array.reverse()
brray.reverse()

res = 0
time = 0

while time <= k:
    if len(array) > 0 and len(brray):
        if array[-1] < brray[-1]:
            time += array.pop()
        else:
            time += brray.pop()
    elif len(array) > 0:
        time += array.pop()
    elif len(brray) > 0:
        time += brray.pop()
    else:
        break
    if time <= k:
        res += 1

print(res)

Submission status: Wrong Answer

Solution code:
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    A.append(100000000000)
    B.append(100000000000)
    a, b = 0, 0
    answer = 0

    while True:
        if (a < N and A[a] < B[b]) or b == M:
            going_to_read = A[a]
            a += 1
        else:
            going_to_read = B[b]
            b += 1

        if K >= going_to_read:
            answer += 1
            K -= going_to_read
        else: break

        if a == N and b == M: break

    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
x = input().split()
N = int(x[0])
M = int(x[1])
K = int(x[2])
T = 0
N = 0
A = input().split()
B = input().split()
A.append(10000000000)
B.append(10000000000)

while K > T:
    if int(A[0]) < int(B[0]):
        if T + int(A[0]) > K:
            break
        T += int(A[0])
        N += 1
        del A[0]

    else:
        if T + int(B[0]) > K:
            break
        T += int(B[0])
        N += 1

        del B[0]
print(N)

Submission status: Wrong Answer

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()]

if sum(A) + sum(B) <= K:
    print(N+M)
else:
    total = 0
    ans = 0
    a = 0
    b = 0
    while total <= K and (a < N or b < M):
        if a < N and b < M:
            if A[a] <= B[b]:
                total += A[a]
                ans += 1
                a += 1
            else:
                total += B[b]
                ans += 1
                b += 1
        elif a >= len(A):
            total += B[b]
            ans += 1
            b += 1
        elif b >= len(B):
            total += A[a]
            ans += 1
            a += 1
        else:
            ans += 1
            break
    print(ans-1)

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
tmp = 0
while True:
    if A and B:
        if A[0] < B[0]:
            if tmp+A[0] <= K:
                ans += 1
                tmp += A.pop(0)
            else:
                break
        else:
            if tmp+B[0] <= K:
                ans += 1
                tmp += B.pop(0)
            else:
                break
    elif A:
        if tmp+A[0] <= K:
            ans += 1
            tmp += A.pop(0)
    elif B:
        if tmp+B[0] <= K:
            ans += 1
            tmp += B.pop(0)
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
a=input().split(" ")
b=input().split(" ")
c=input().split(" ")
d=0
e=0
f=0
count=0
while int(a[2])>=e and int(a[2])>=int(b[0]):
    if d<int(a[0]):
        e=e+int(b[d])
        d=d+1
        count+=1
    elif f<int(a[1]) and d>=3:
        e=e+int(c[f])
        f=f+1
        count+=1
    elif d>=int(a[0]) and f>=int(a[1]):
        d=0 
        f=0
    else:
        break

print(count)

Submission status: Wrong Answer

Solution code:
import sys
nums=input().split()
a=int(nums[0])
b=int(nums[1])
n=int(nums[2])
lista=input().split()
listb=input().split()
listall=[]

acount=0
bcount=0
count=0
time=0
for i in lista:
  anum=int(i)
  for j in range(bcount,b):
    bnum=int(listb[j])
    if anum<bnum:
      listall.append(anum)
      break
    else:
      listall.append(bnum)
      bcount+=1

if bcount!=b:
  for i in range(bcount,b):
    listall.append(int(listb[i]))

for i in listall:
  if i+time>n:
    print(count)
    sys.exit()
  else:
    time+=i
    count+=1
print(count)

Submission status: Wrong Answer

Solution code:
import sys
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.append("1000000001")
b.append("1000000001")
a[n]=int(a[n])
b[m]=int(b[m])

x=0
y=0
ans=0
time=0

for i in range(n+m):
    if a[x]<=b[y]:
        time+=a[x]
        if time>k:
            time-=a[x]
            print(ans)
            sys.exit()
        x+=1
        ans+=1
    else:
        time+=b[y]
        if time>k:
            time-=b[y]
            print(ans)
            sys.exit()   
        y+=1
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n_m_k = input().split()
n = int(n_m_k[0])
m = int(n_m_k[1])
k = int(n_m_k[2])

a_str_list = input().split()
a_int_list = [int(x) for x in a_str_list]

b_str_list = input().split()
b_int_list = [int(x) for x in b_str_list]

sum_t = 0
cnt_a = 0
cnt_b = 0
while(sum_t <= k):
    if(False):
        break
    else:
        if((cnt_a != len(a_int_list)) and (cnt_b != len(b_int_list))):
            if(a_int_list[cnt_a] < b_int_list[cnt_b]):
                sum_t += a_int_list[cnt_a]
                if(sum_t <= k):
                    cnt_a += 1
                else:
                    break
            else:
                sum_t += b_int_list[cnt_b]
                if(sum_t <= k):
                    cnt_b += 1
                else:
                    break
        elif(cnt_a < len(a_int_list)):
            sum_t += a_int_list[cnt_a]
            if(sum_t <= k):
                cnt_a += 1
            else:
                break
        elif(cnt_b < len(b_int_list)):
            sum_t += b_int_list[cnt_b]
            if(sum_t <= k):
                cnt_b += 1
            else:
                break
        else:
            break

print(cnt_a + cnt_b)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
A = [int(n) for n in input().split()]
B = [int(n) for n in input().split()]

ans = 0

while K > 0:

    if len(A) == 0 and len(B) == 0:
        break

    elif len(A) == 0:
        X = B[0]
        B.pop(0)

    elif len(B) == 0:
        X = A[0]
        A.pop(0)

    else:
        X = min(A[0],B[0])

        if X == A[0]:
            A.pop(0)
        else:
            B.pop(0)


    if K < X:
        break

    ans += 1
    K -= X

print(ans)

Submission status: Wrong Answer

Solution code:

n, m, k = map(int, input().split())
from bisect import bisect_right

a = list(map(int, input().split()))
b = list(map(int, input().split()))
total_a = [0] * n
total_b = [0] * m

def set_data(data, a, x):
    data[0] = a[0]
    for i in range(1, x):
        data[i] = data[i - 1] + a[i]

set_data(total_a, a, n)
set_data(total_b, b, m)
ans = 0

for i in range(n - 1, -1, -1):
    if total_a[i] < k:
        index = bisect_right(total_b, k - total_a[i], 0, m)
        time = total_b[index - 1]
        ans = max(ans, i + index + 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 = 0

A.reverse()
B.reverse()

while (True):
    a = len(A) - 1
    b = len(B) - 1
    if a >= 0 and b >= 0:
        if A[a] < B[b] and A[a] <= K:
            K -= A.pop(a)
            c += 1

        elif B[b] <= K:
            K -= B.pop(b)
            c += 1

        else:
            break

    elif a >= 0:
        if A[a] <= K:
            K -= A.pop(a)
            c += 1

        else:
            break
    
    elif b >= 0:
        if B[b] <= K:
            K -= B.pop(b)
            c += 1

        else:
            break
    else:
        break

print(c)

Submission status: Wrong Answer

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

# N = [3 ,4, 730]
# A = [60, 90, 120]
# B = [80, 150, 80, 150]

M = N[1]
K = N[2]
N = N[0]

s = 0
c1 = 0
c2 = 0

s1 = [sum(A[:k+1]) for k in range(N)]
s2 = [sum(B[:k+1]) for k in range(M)]

C = [0]
for i in range(N):
    k = 0
    while s2[k] <= K-s1[i]:
        k += 1
        if k == M:
            break
    C.append(k+i+1)

print(max(C))

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()))
s = 0
ans = 0

while True:
    x = 10**10
    y = 10**10
    if len(a) > 0:
        x = a[0]
    if len(b) > 0:
        y = b[0]

    if x < y:
        s += a.pop(0)
    else:
        s += b.pop(0)
    '''else:
        for i in range(min(len(a),len(b))-1):
            if a[i+1] < b[i+1]:
                s += a.pop(0)
                break
            elif a[i+1] > b[i+1]:
                s += b.pop(0)
                break
            if i+1 == min(len(a),len(b))-1:
                s += a.pop(0)'''

    if s > k:
        break

    ans += 1

    if ans == n+m:
        break

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()]
l=[]
s=0
c=0
for i in a:
    l.append(i)
for i in b:
    l.append(i)
l.sort()
for i in l:
    if(s+i<=k):
        s+=i
        c+=1
    else:
        break
print(c)

Submission status: Wrong Answer

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

A = []
B = []

tmp = 0
for i in AStr:
    tmp += int(i)
    if (tmp > K):
        break
    A.append(int(i))

tmp = 0
for i in BStr:
    tmp += int(i)
    if (tmp > K):
        break
    B.append(int(i))

num = 0
tmp = 0
maxNum = len(A)
if maxNum < len(B):
    maxNum = len(B)

for i in range(len(A)+1):
    num = 0
    tmp = 0
    for j in range(i):
        tmp += A[j-1]
        num += 1
    for k in B:
        tmp += k
        if (tmp > K):
            if maxNum < num:
                maxNum = num
            continue
        num += 1

print(num)

Submission status: Wrong Answer

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

while i<len(a) and j<len(b):
	if a[i]<=b[j]:
		c.append(a[i])
		i+=1 
	else:
		c.append(b[j])
		j+=1 

while i<len(a):
	c.append(a[i])
	i+=1 
while j<len(b):
	c.append(b[j])
	j+=1 
#print(c)
i=0 
ans=-1
s=0
#print(kk)
while i<len(c):
	s=s+c[i]
	if s==kk:
		ans=i 
		break 
	if s>kk:
		ans=i-1 
		break 
	i+=1
if kk>=s:
	print(len(c))
else:
	print(ans+1)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

N, M, K = map(int, input().split())
A = np.array(list(map(int, input().split())), dtype='int64')
B = np.array(list(map(int, input().split())), dtype='int64')
AB = np.concatenate([A, B], 0)
AB = np.sort(AB)
AB_total = AB.cumsum()

answer = (AB_total <= K).sum()

print(answer)

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()))

accum_a = []
sum_sofar = 0
for ae in a:
  sum_sofar += ae
  if sum_sofar > k:
    break
  accum_a.append(sum_sofar)
  
accum_b = []
sum_sofar = 0
for be in b:
  sum_sofar += be
  if sum_sofar > k:
    break
  accum_b.append(sum_sofar)

if len(accum_a) == 0:
  ans = len(accum_b)
elif len(accum_b) == 0:
  ans = len(accum_a)
elif (accum_a[-1] + accum_b[-1] <= k):
  ans = m + n
else:
  cands = []
  for i, ae in enumerate(accum_a):
    for j, be in enumerate(accum_b):
      if ae + be > k:
        cands.append(i + j + 1)
        break
  if len(cands) == 0:
    ans = 0
  else:
    ans = max(cands)
    
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()))
# al, bl = [0], [0]
ans = 0
while (True):
    if (not a) and (not b):
        break
    elif a and b:
        if a[0] <= b[0]:
            k-=a.popleft()
        elif a[0] > b[0]:
            k-=b.popleft()
    elif a and (not b):
        k-=a.popleft()
    elif b and (not a):
        k-=b.popleft()
    if k<0:
        break
    else:
        ans+=1
print(ans)

Submission status: Wrong Answer

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()]
cont = 0
p,u = 0,0
while k>0 and p!=n and u!=m:
    #if p == n-1 or u == m-1: break
    if a[p] <= b[u]:
        k-=a[p]
        if k<0: break
        p+=1
        cont+=1
    else:
        k-=b[u]
        if k<0: break
        u+=1
        cont+=1
    #print(k,p,u)
#beleza, agora acabou uma das estantes
while p<=n-1 and k>0:
    k-=a[p]
    if k<0: break
    p+=1
    cont+=1
        
while u<=m-1 and k>0:
    k-=b[u]
    if k<0: break
    u+=1
    cont+=1

print(cont)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]"):
    candidateA = []
    weightA = 0
    for a in A:
        if weightA + a > K:
            break
        else:
            candidateA.append(a)
            weightA += a
    max_count = current_count = len(candidateA)

    candidateB = []
    weightB = 0
    terminated=False
    for b in B:
        if terminated == True and weightA + weightB > K:
            break

        if len(candidateA)==0:
            break

        if weightA + weightB + b <= K:
            weightB += b
            candidateB.append(b)
            current_count += 1

        elif terminated==False:
            while weightA + weightB + b > K:
                if len(candidateA)>0:
                    weightA -= candidateA.pop()
                    current_count -= 1
                else:
                    terminated=True
            if terminated == True:
                continue
            else:
                weightB += b
                candidateB.append(b)
                current_count += 1
        max_count = max(max_count, current_count)

    print(max_count)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, K, A, B)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import copy
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_check = copy.deepcopy(A)
B_check = copy.deepcopy(B)

count = 0
book = 0
while True:
  if len(A) == len(B) == 0:
    break
  elif len(A) == 0:
    count += B[0]
    B.pop(0)
  elif len(B) == 0:
    count += A[0]
    A.pop(0)
  else:
    if A[0] < B[0]:
      count += A[0]
      A.pop(0)
    elif A[0] >= B[0]:
      count += B[0]
      B.pop(0)
  if count >= K:
    break
  book += 1

for i in range(len(A_check)):
  if A_check[i] > 1000000000:
    book = 0
for i in range(len(B_check)):
  if B_check[i] > 1000000000:
    book = 0
if N > 200000:
  book = 0
if M > 200000:
  book = 0
if K > 1000000000:
  book = 0

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()))

time,cnt=0,0
i,j=0,0
while(time<K and (i<N or j<M)):
    if i==N:
        if B[j]+time>K:
            break
        time+=B[j]
        j+=1
        cnt+=1
    elif j==M:
        if A[i]+time>K:
            break
        time+=A[i]
        i+=1
        cnt+=1
    else:
        if A[i]<B[j]:
            if A[i]+time>K:
                break
            time+=A[i]
            i+=1
            cnt+=1
        elif A[i]>B[j]:
            if B[j]+time>K:
                break
            time+=B[j]
            j+=1
            cnt+=1
        else:
            if A[i]+time>K:
                break
            if i==N-1:
                time+=B[j]
                j+=1
                cnt+=1
            elif j==M-1:
                time+=A[i]
                i+=1
                cnt+=1
            else:
                if A[i+1]<B[j+1]:
                    time+=A[i]
                    i+=1
                    cnt+=1
                else:
                    time+=B[j]
                    j+=1
                    cnt+=1
print(cnt)

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()]
i, j = 0, 0
c = 0
f = 0
while(i < len(a) and j < len(b)):
    if(a[i] < b[j]):
        if((c + a[i]) <= k):
            c += a[i]
            f += 1
            i += 1
        else:   break    
    else:
        if((c + b[j]) <= k):
            c += b[j]
            f += 1
            j += 1
        else:
            break
if(i < len(a) and i != (len(a) - 1)):
    while(i < len(a)):
        if((c + a[i]) <= k):
            c += a[i]
            f += 1
            i += 1
        else:
            break
if(j < len(b) and j != (len(b) - 1)):
    while(j < len(b)):
        if((c + b[j]) <= k):
            c += b[j]
            f += 1
            j += 1
        else:
            break
print(f)

Submission status: Wrong Answer

Solution code:
n, m, k=map(int, input().split())
a=list(map(int, input().split()))+[10**10]*(10**6)
b=list(map(int, input().split()))+[10**10]*(10**6)

loop=max(n, m)
i=0
j=0
T=0
ans=0

for t in range(2*loop):
    if a[i]>=b[j]:
        T+=b[j]
        if T<=k:
            ans+=1
            j+=1
        else:
            print(ans)
            exit()
    elif b[j]>a[i]:
        T+=a[i]
        if T<=k:
            ans+=1
            i+=1
        else:
            print(ans)
            exit()
    
    elif i==n-1:
        T+=b[j]
        if T<=k:
            ans+=1
            j+=1
        else:
            print(ans)
            exit()
    
    elif j==m-1:
        T+=a[i]
        if T<=k:
            ans+=1
            i+=1
        else:
            print(ans)
            exit()