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:
N,M,K = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
subseqA = [0] # i th element is sum of first i books
subseqB = [0]
for elem in a:
    subseqA.append(subseqA[-1]+elem)
for elem in b:
    subseqB.append(subseqB[-1]+elem)
maxBooks = 0
curABooks = 0
curBBooks = 0
for i in range(N+1):
    if K < subseqA[i]:
        curABooks = i - 1
        maxBooks = i - 1
        break
if subseqA[N] <= K:
    curABooks = N
for i in range(curABooks,-1,-1):
    for j in range(curBBooks + 1,M+1):
        if subseqA[i] + subseqB[j] > K:
            curBBooks = j - 1
            break
    if subseqA[i] + subseqB[M] <= K:
        curBBooks = M
    if i + curBBooks > maxBooks:
        maxBooks = i + curBBooks
print(maxBooks)
print(curBBooks)

Submission status: Wrong Answer

Solution code:
# import io
# import sys

# _INPUT = """\
# 3 4 730
# 60 90 120
# 80 150 80 150

# 3 4 240
# 60 90 120
# 80 150 80 150

# 1 4 120
# 100 1 1 1 1 1 1 1 1 1 1
# 80 10 10 10 10
# """
# sys.stdin = io.StringIO(_INPUT)

####################################################################
import sys
def p(*_a):
  return
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
####################################################################

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


# 累積和
from itertools import accumulate
C = accumulate(A)
D = accumulate(B)

E = []
F = []
for c in C:
  if c > K: break
  E.append(c)

for d in D:
  if d > K: break
  F.append(d)

p(*E)
p(*F)

c = d = 0
ans = k = 0

for i, e in enumerate(E):
  for j, f in enumerate(F):
    if e + f <= K:
      ans = max(ans, i+1+j+1)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import accumulate

def Main():
    n,m,k = map(int,sys.stdin.readline().rstrip().split())
    a = list(accumulate(map(int,sys.stdin.readline().rstrip().split())))
    b = list(accumulate(map(int,sys.stdin.readline().rstrip().split())))
    ans = 0
    for i in range(n):
        item = a[i]
        if k<item:  break
        c = i+1
        for jtem in b:
            if k<item+jtem:
                break
            c += 1
        ans = max(ans,c)
        i = ans
    print(ans)
    return

if __name__=='__main__':
    Main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

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

cnt = 0

c = deque(a)
d = deque(b)

i = c.popleft()
j = d.popleft()

while k >= 0:
    if i > j:
        k -= j
        if len(d) == 0:
            j = 10**10
        else:
            j = d.popleft()
    else:
        k -= i
        if len(c) == 0:
            i = 10**10
        else:
            i = c.popleft()

    if k < 0:
        break
    elif i == 10**10 and j == 10**10:
        cnt += 1
        break

    cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from scipy.sparse.csgraph import floyd_warshall
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations, combinations_with_replacement
from heapq import heappop, heappush, heapify
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n,m,k = inpm()
    a = inpl()
    b = inpl()
    cnt = 0
    sumation = 0
    indexa = 0
    indexb = 0
    while sumation <= k:
        if indexa < n and indexb < m:
            if min(a[indexa],b[indexb]) + sumation > k:
                break
            if a[indexa] > b[indexb]:
                cnt += 1
                sumation += b[indexb]
                indexb += 1
            else:
                cnt += 1
                sumation += a[indexa]
                indexa += 1
        elif indexa == n and indexb < m:
            if b[indexb] + sumation > k:
                break
            cnt += 1
            sumation += b[indexb]
            indexb += 1
        elif indexa < n and indexb == m:
            if a[indexa] + sumation > k:
                break
            cnt += 1
            sumation += a[indexa]
            indexa += 1
        else:
            break
    print(cnt)
        
if __name__ == "__main__":
    main()

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
ai=0
bi=0
for i in range(n+m):
  ans+=1
  if n-ai==0:
    k-=b[bi]
    bi+=1
  elif m-bi==0:
    k-=a[ai]
    ai+=1
  elif a[ai]>b[bi]:
    k-=b[bi]
    bi+=1
  elif b[bi]>a[ai]:
    k-=a[ai]
    ai+=1
  else:
    if n==ai+1:
      k-=b[bi]
      bi+=1
    elif m==bi+1:
      k-=a[ai]
      ai+=1
    elif a[ai+1]>=b[bi+1]:
      k-=b[bi]
      bi+=1
    elif a[ai+1]<b[bi+1]:
      k-=a[ai]
      ai+=1
  if k<0:
    ans-=1
    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()))
i=0
j=0
count=0
M=0

while M<=k:
  if i>len(A)-1:
    M+=B[j]
    j+=1
  elif j>len(B)-1:
    M+=A[i]
    i+=1
  elif min(A[i],B[j])==A[i]:
    M+=A[i]
    if i<len(A)-1:
      i+=1
  elif min(A[i],B[j])==B[j]:
    M+=B[j]
    if j<len(B)-1:
      j+=1  
  else:
    M+=A[i]
    if i<len(A)-1:
      i+=1
  if M>k:
        break
  count+=1
print(count)

Submission status: Wrong Answer

Solution code:
from sys import stdin

A=list(map(int,stdin.readline().split()))
N=A[0]
M=A[1]
K=A[2]
B=list(map(int,stdin.readline().split()))  #N
C=list(map(int,stdin.readline().split()))  #M

Nlist=list()
Mlist=list()
sum=0

for u in B:
    sum+=u
    if sum>K:
        break
    Nlist.append(sum)


sum=0
O=0

for v in C:
    sum+=v
    if sum>K:
        break
    Mlist.append(sum)

if len(Mlist)==0 and len(Nlist)==0:
    print(0)
    O=1

if O==0:
    if len(Mlist)==0:
        print(len(Nlist))
        O=1
    if len(Nlist)==0:
        print(len(Mlist))
        O=1
    if Mlist[len(Mlist)-1]+Nlist[len(Nlist)-1]<=K:
        print(len(Mlist)+len(Nlist))
        O=1

MAX=2
mbegin=0
mend=len(Mlist)-1
archive=0
# print(Nlist)
# print(Mlist)



if O==0:

    for u in range(len(Nlist)-1,-1,-1):
        mend=len(Mlist)-1
        K=K-Nlist[u]
        MAX=max(MAX,u+1)
        #print(K)
        #binary search
        if Mlist[mbegin]<=K:
            UU=(mbegin+mend)//2

            while mbegin!=mend:
                if Mlist[UU]<=K:
                    K-=Mlist[UU]
                    mbegin=UU
                else:
                    mend=UU

            if mbegin==archive:
                if mbegin==0:
                    MAX=max(MAX,u+2)
                break

            MAX=max(MAX,u+mbegin+2)
            archive=mbegin

if O==0:
   print(MAX)

Submission status: Wrong Answer

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

rui_A = [0 for _ in range(N)]
rui_B = [0 for _ in range(M)]



rui_A[0] = A[0]
for i in range(N-1):
    rui_A[i+1] = rui_A[i] + A[i]

rui_B[0] = B[0]
for i in range(M-1):
    rui_B[i+1] = rui_B[i] + B[i]

rui_A.insert(0,0)
rui_B.insert(0,0)

max_book = 0
for i in range(len(rui_A)):
    if rui_A[i] <= K:
        nokori = K - rui_A[i]
        B_posi = bisect.bisect_right(rui_B,nokori)
        if max_book < B_posi + i:
            max_book = B_posi + i - 1
print(max_book)

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 = N
    b_idx = M
    ans = 0

    A = list(accumulate([0] + A))
    B = list(accumulate([0] + B))

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

    # print(a_idx, b_idx)
    # print(ans)
    print(M + N - ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

import sys

def main2():
    n,m,k = map(int,input().split())
    a_desk_list=[]
    b_desk_list=[]
    a_desk_list = list(map(int,input().split()))
    b_desk_list = list(map(int,input().split()))
    if k < a_desk_list[0] and k < b_desk_list[0]:
        print(0)
        exit
    elif k > sum(a_desk_list)+sum(b_desk_list):
        print(n+m)
        exit
    else:
        for i in range(n):
            if k > sum(a_desk_list[:i]):
                tmp_i=i
            else:
                continue
        for j in range(m):
            if k > sum(a_desk_list[:tmp_i])+sum(b_desk_list[:j]):
                continue
            else:
                break
        print(tmp_i+j)

if __name__ == "__main__":
    main2()

Submission status: Wrong Answer

Solution code:
# from pprint import pprint
# import math
# import collections

# n = int(input())
n, m, k = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))

total = 0
t = 0
cnt = 0

ai = 0
bi = 0

while True:
    if a and b:
        if a[ai] < b[bi]:
            total += a[ai]
            cnt += 1

            if ai + 1 > n-1:
                a = None
            else:
                ai += 1
        else:
            total += b[bi]
            cnt += 1

            if bi + 1 > m-1:
                b = None
            else:
                bi += 1
    elif a:
        total += a[ai]
        cnt += 1

        if ai + 1 > n-1:
            a = None
        else:
            ai += 1
    elif b:
        total += b[bi]
        cnt += 1

        if bi + 1 > m-1:
            b = None
        else:
            bi += 1
    else:
        break

    total += t

    if total > k:
        cnt -= 1
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
i = list(map(int, input().split()))
n=i[0]
m=i[1]
k=i[2]
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a=b=0 #それぞれの読んだ数
cal=0 #読んだ時間
if max(A)>1000000000 or max(B)>1000000000 or k>1000000000:
    print(0)
else:
    while True:
        if a!=n and b!=m:
            if A[a]<=B[b]:
                cal+=A[a]
                if cal>k:
                    break
                a+=1
            elif B[b]<A[a]:
                cal+=B[b]
                if cal>k:
                    break
                b+=1
        elif a==n and b==m:
            break
        elif a==n and b!=m:
            cal+=B[b]
            if cal>k:
                break
            b+=1
        elif a!=n and b==m:
            cal+=A[a]
            if cal>k:
                break
            a+=1
    print(a+b)

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
aindex=n+1
bindex=m+1
acumsum = [0]
bcumsum = [0]

ab =0
for aa in range(n):
  ab += a[aa]
  acumsum.append(ab)# = ab
  if ab>k:
    aindex= aa
    break

ab =0
for bb in range(m):
  ab += b[bb]
  bcumsum.append(ab)
  if ab>k:
    bindex= bb
    break

# print(acumsum,bcumsum)
from bisect import bisect_left
for i in range(aindex):
  j = bisect_left(bcumsum, k-acumsum[i])
  # print(i,j)
  ans = max(ans, i+j)
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()))  
sum_A = [0]
sum_B = [0]
for a in range(len(A)):
    sum_A.append(sum_A[a]+A[a])

for b in range(len(B)):
    sum_B.append(sum_B[b]+B[b])

len_A = len(sum_A)
len_B = len(sum_B)
ans = 0
for i in range(len_A):
    a = sum_A[i]
    if a > K:
        break
    for j in range(len_B):
        b = sum_B[j]
        if b > K:
            break
        if a + b > K:
            break
        ans = i+j

print(ans)

Submission status: Wrong Answer

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

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

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

A.append(-1)
B.append(-1)

re = i = 0


while(m > 0 and i < a+b):
    if(A[0] < B[0]):
        if(A[0] > 0):
            s = A[0]
            del A[0]            
        else:
            s = B[0]
            del B[0]
    else:
        if(B[0] > 0):
            s = B[0]
            del B[0]
        else:
            s = A[0]
            del A[0]
    m -= s
    if(m >= 0):
        re += 1
        i+=1
print(re)

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
while k>=0:
    if len(a)==0 and len(b)!=0:
        if k>=b[0]:
            ans+=1
            k-=b[0]
            del b[0]
        else:
            break
    elif len(a)!=0 and len(b)==0:
        if k>=a[0]:
            ans+=1
            k-=a[0]
            del a[0]
        else:
            break
    elif len(a)==0 and len(b)==0:
        break
    else:
        mi=min(a[0],b[0])
        if mi>k:
            break
        ans+=1
        k-=mi
        if a[0]>b[0]:
            del b[0]
        elif a[0]<b[0]:
            del a[0]
        else:
            if len(a)==1:
                del b[0]
            elif len(b)==1:
                del a[0]
            else:
                if a[1]>b[1]:
                    del b[0]
                elif a[1]<b[1]:
                    del a[0]
                else:
                    if len(a)==2:
                        del b[0]
                    elif len(a)==2:
                        del a[0]
                    else:
                        if a[2]>=b[2]:
                            del b[0]
                        else:
                            del a[0]
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()))

ind_A = 0
ind_B = 0
ans = 0
time = 0

for i in range(1, N+M+1):

    if (ind_B >= M and ind_A < N): # Bを読み終わったからAの本を読む
        time += A[ind_A]
        ind_A += 1
        ans += 1
    elif (ind_A >= N and ind_B < M) : # Aを読み割ったからBの本を読む
        time += B[ind_B]
        ind_B += 1
        ans += 1
    elif  A[ind_A] <= B[ind_B]: #Aの方が先に読み終わるからAの本を読む
        time += A[ind_A]
        ind_A += 1
        ans += 1
    elif A[ind_A] > B[ind_B]: #Bの方が先に読み終わるからBの本を読む
        time += B[ind_B]
        ind_B += 1
        ans += 1
    
    if i < N+M:
        next_b = 0
        if (ind_B >= M and ind_A < N): # Bを読み終わったからAの本を読む
            next_b += A[ind_A]
        elif (ind_A >= N and ind_B < M) : # Aを読み割ったからBの本を読む
            next_b += B[ind_B]
        elif  A[ind_A] <= B[ind_B]: #Aの方が先に読み終わるからAの本を読む
            next_b += A[ind_A]
        elif A[ind_A] > B[ind_B]: #Bの方が先に読み終わるからBの本を読む
            next_b += B[ind_B]
    
        if time + next_b > K:
            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()))
subseqA = [0] # i th element is sum of first i books
subseqB = [0]
for elem in a:
    subseqA.append(subseqA[-1]+elem)
for elem in b:
    subseqB.append(subseqB[-1]+elem)
maxBooks = 0
curABooks = 0
curBBooks = 0
for i in range(N+1):
    if K < subseqA[i]:
        curABooks = i - 1
        maxBooks = i - 1
        break
for i in range(curABooks,-1,-1):
    for j in range(curBBooks + 1,M+1):
        if subseqA[i] + subseqB[j] > K:
            curBBooks = j - 1
            break
    if subseqA[i] + subseqB[M] <= K:
        curBBooks = M
    if i + curBBooks > maxBooks:
        maxBooks = i + curBBooks
print(maxBooks)

Submission status: Wrong Answer

Solution code:
import numpy as np
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
while True:
    if len(a) and len(b):
        if a[0] < b[0] and k >= a[0]:
            k-=a[0]
            del a[0]
            ans+=1
        elif a[0] >= b[0] and k >= b[0]:
            k-=b[0]
            del b[0]
            ans+=1
        else:
            print(ans)
            exit()
    elif len(a)==0 and len(b)==0:
        print(ans)
        exit()
    elif len(a)==0 and k >= b[0]:
        k-=b[0]
        del b[0]
        ans+=1
    elif len(b)==0 and a[0] <= k:
        k-=a[0]
        del a[0]
        ans+=1
    else:
        print(ans)
        exit()

Submission status: Wrong Answer

Solution code:
def compInt_Int(intA, intB):
    if (intA < intB):
        return '1'
    return '2'

s = input().split()
intN = int(s[0])
intM = int(s[1])
intK = int(s[2])

inListA = list(map(int,input().split()))
inListB = list(map(int,input().split()))

maxCntListA = len(inListA)
maxCntListB = len(inListB)

cntSum = maxCntListA + maxCntListB

cnt = 0
readCnt = 0
readTime = 0
while cnt < cntSum:
    if(len(inListA) > 0 and len(inListB) > 0):
        reInt = compInt_Int(inListA[0], inListB[0])
        if (reInt == '1'):
            if (readTime + inListA[0] > intK):
                print(readCnt)
                exit()
            readTime += inListA[0]
            inListA.remove(inListA[0])
            readCnt += 1
        else:
            if (readTime + inListB[0] > intK):
                print(readCnt)
                exit()
            readTime += inListB[0]        
            inListB.remove(inListB[0])
            readCnt += 1
        cnt += 1
    elif(len(inListA) > 0):
        if (readTime + inListA[0] > intK):
            print(readCnt)
            exit()
        readTime += inListA[0]
        inListA.remove(inListA[0])
        readCnt += 1
        cnt += 1
    elif(len(inListB) > 0):
        if (readTime + inListB[0] > intK):
            print(readCnt)
            exit()
        readTime += inListB[0]
        inListB.remove(inListB[0])
        readCnt += 1
        cnt += 1
print(readCnt)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# 日本語を入力できるようにするために上記一文が必要


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

read_time = 0
read_count = 0
while read_time < k:
        if not a_list and not b_list:
                break
        elif not a_list and b_list:
                read_count += 1
                read_time += b_list[0]
                b_list.remove( b_list[0])
        elif a_list and not b_list:
                read_count += 1
                read_time += a_list[0]
                a_list.remove( a_list[0])
        elif a_list[0] <= b_list[0]:
                read_time += a_list[0]
                a_list.remove( a_list[0])
                read_count += 1
        else:
                read_time += b_list[0]
                b_list.remove( b_list[0])
                read_count += 1

print(read_count)

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


count=0
count_min=0
value=0
for item in a_list :
  value+=item
  count+=1
  current=count

  cure_value=value
  for item2 in b_list :
    if cure_value+item2<=k :
      current+=1
      cure_value+=item2
  count_min=max(count_min,current)


print(count_min)

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 = 0
b = 0
ans = 0
sumA = 0
sumB = 0
for i in range(len(A)):
  if sumA + A[i] <= k:
    a += 1
  else:
    break
 
for i in range(len(B)):
  if sumB +B[i] <= k:
    b += 1
  else:
    break
#print(a)
#print(b)
 
su = sum(A[0:a]) + sum(B[0:b])
if su <= k:
  print(a+b)
else:
  for i in range(min(a,b)):
    ans += 1
    if A[a-1] >= B[b-1]:
      if su - A[a-1] <= k:
        break
      else:
        a -=1
    elif A[a-1] < B[b-1]:
      if su - B[b-1] <= k:
        break
      else:
        b -=1   
  print(a+b)

Submission status: Wrong Answer

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

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

n_l = list(map(int, input().split()))
m_l = list(map(int, input().split()))

cnt_book = 0
cnt_time = 0

ni = 0
mi = 0

while cnt_time < k:
    if  n == ni and m == mi:
        break
    elif n > ni and m == mi:
        if cnt_time + n_l[ni] <= k:
            cnt_book = cnt_book + 1                     
            cnt_time = cnt_time + n_l[ni]
            ni = ni + 1
        else:
            break
    elif n == ni and m > mi:
        if cnt_time + m_l[mi] <= k:
            cnt_book = cnt_book + 1
            cnt_time = cnt_time + m_l[mi]
            mi = mi + 1
        else:
            break
    else:
        if n_l[ni] <= m_l[ni]:
            if cnt_time + n_l[ni] <= k:
                cnt_book = cnt_book + 1
                cnt_time = cnt_time + n_l[ni]
                ni = ni + 1
            else:
                break
        else:
            if cnt_time + m_l[mi] <= k:
                cnt_book = cnt_book + 1
                cnt_time = cnt_time + m_l[mi]
                mi = mi + 1
            else:
                break
print(cnt_book)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_right

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

ans = 0
for i, a in enumerate(A):
    if a > K:
        break
    n = bisect_right(B, K-a)
    ans = max(ans, i+n+1)

print(ans)

Submission status: Wrong Answer

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

n = 0
i = 0
while n < K:
    if len(list_A) == 0 and len(list_B) == 0:
        break
    else:
        if len(list_A) == 0 and len(list_B) != 0:
            n += list_B.pop(0)
            i += 1
        elif len(list_B) == 0 and len(list_A) != 0:
            n += list_A.pop(0)
            i += 1
        elif list_A[0] <= list_B[0]:
            n += list_A.pop(0)
            i += 1
        else:
            n += list_B.pop(0)
            i += 1

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

A = deque(A)
B = deque(B)

cnt = 0
time = 0
while True:
  
  if len(A) > 0 and len(B) > 0:
    if A[0] <= B[0]:
      c = A.popleft()
    else:
      c = B.popleft()
  elif len(A) == 0 and len(B) > 0:
    c = B.popleft()
  elif len(B) == 0 and len(A) > 0:
    c = A.popleft()
  else:
    break
  
  if time+c <= K:
    cnt += 1
    time += c
  else:
    break

print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
    n, m, k = map(int,input().split())
    from collections import deque
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    l = []
    inf = 10**18
    if sum(a)+sum(b) <= k:
        print(m+n)
        return 0
    if a[0] > k and b[0] > k:
        print(0)
        return 0
    for i in range(max(m,n)):
        if i < n:
            c = a[i]
        else:
            c = inf
        if i < m:
            d = b[i]
        else:
            d = inf
        l.append(min(c,d))
        l.append(max(c,d))
    cnt = 0
    for i in range(len(l)):
        k -= l[i]
        if k >= 0:
            cnt += 1
        if k <= 0:
            break
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

from collections import deque

an = list(map(int, input().split()))

bn = list(map(int, input().split()))

accum_a = [0]
accum_b = [0]


for a_i in range(0,len(an)):


    sumCandidate = accum_a[-1] + an[a_i]
    if sumCandidate > k:
        break
    accum_a.append(sumCandidate)

for b_i in range(0,len(bn)):
    i_ = accum_b[-1] + bn[b_i]
    if i_ > k:
        break
    accum_b.append(i_)


def Find(a, b, k1):
    if a[-1] + b[-1] <= k1:
        return len(a) - 1 + len(b) - 1

    if len(a) > len(b):
        rest = k1 - a[-1]
        for i in range(len(b)):
            if rest <= b[-i]:
                return len(a) - 1 + len(b) - 1 - i

    if len(b) > len(a):
        rest = k1 - b[-1]
        for i in range(len(a)):
            if rest <= a[-i]:
                return len(b) - 1 + len(a) - 1 - i

    if a[-1] > b[-1]:
        rest = k1 - b[-1]
        return Find(a, b[0:len(b)-1], rest)+1

    rest = k1 - a[-1]
    return Find(a[0:len(a)-1],b,rest)+1

print(Find(accum_a, accum_b, k))

Submission status: Wrong Answer

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

  A.reverse()
  B.reverse()

  l = len(A) + len(B)

  tot = []
  elapsed = 0
  ans = 0

  for _ in range(l):
    if(A[-1] <= B[-1]):
      tot.append(A.pop())
    else:
      tot.append(B.pop())

    if(len(A) == 0):
      tot = tot + B
      break

    if(len(B) == 0):
      tot = tot + A
      break 

  tot.append(0)

  for i in range(0, len(tot) - 1):
    if(tot[i] > tot[i+1]):
      tot[i], tot[i+1] = tot[i+1], tot[i]

    elapsed += tot[i]

    if(elapsed > K):
      break

    ans += 1 

  print(ans)


if __name__ == "__main__":
  main()

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

count = 0
total = 0
idxA = -1
idxB = -1

for i in range(N):
  t = total + A[i]
  if t > K:
    break
  total = t
  count += 1
  idxA = i

for i in range(M):
  t = total + B[i]
  if t > K:
    break
  total = t
  count += 1
  idxB = i

max_total = total
ans = count

# print((total, ans, idxA, idxB))

for i in range(idxA, -1, -1):
  total -= A[i]
  count -= 1
  for j in range(idxB+1, M):
    t = total + B[j]
    if t <= K:
      total = t
      count += 1
      idxB = j
      if max_total < total:
        max_total = total
        ans = count
    else:
      break

print(ans)