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

aindex = 0
bindex = 0
timeconsumed = 0
readbooks = 0
L = 10 ** 10
while True:
    if aindex >= n and bindex >= m:
        break
    if aindex >= n:
        atime = L
    else:
        atime = A[aindex]
    if bindex >= m:
        btime = L
    else:
        btime = B[bindex]

    if atime < btime:
        timeconsumed += atime
        aindex += 1
    else:
        timeconsumed += btime
        bindex += 1
    if timeconsumed > k:
        break
    readbooks += 1
print(readbooks)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 標準入力を取得
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

# 求解処理
ans = 0
n, m, k = 0, 0, 0
while True:
    if n >= N and m >= M:
        break
    if n >= N:
        k += B[m]
        if k > K:
            break
        ans += 1
        m += 1
        continue
    if m >= M:
        k += A[n]
        if k > K:
            break
        ans += 1
        n += 1
        continue
    A_n, B_m = A[n], B[m]
    if A_n <= B_m:
        k += A_n
        n += 1
    else:
        k += B_m
        m += 1
    if k > K:
        break
    ans += 1

# 結果出力
print(ans)

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(" "))
A=list(map(int,input().split(" ")))
B=list(map(int,input().split(" ")))

n_A=0
n_B=0
time=0

while time <= K:
  if n_A < N:
    if n_B <M:
      if A[n_A]<B[n_B]:
        time+=A[n_A]
        n_A+=1
      else:
        time+=B[n_B]
        n_B+=1
    else: 
      time+=A[n_A]
      n_A+=1
  elif n_B <M:
    time+=B[n_B]
    n_B+=1
  else:
    n_A+=1
    break


print(n_A+n_B-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()))


time = 0
i=0
k=0

while True:
    
    if i>=N-1 and not k>=M-1:
        time += B[k]
        if time >K:
            print(i+k)
            exit()
        k+=1
    elif k>=M-1 and not i>=N:
        time += A[i]
        if time >K:
            print(i+k)
            exit()
        i += 1
    elif k>=M-1 and i>=N-1:
        print(M+N)
        exit()
    else :
        if A[i]>=B[k]:
            time += B[k]
            if time >K:
                print(i+k)
                exit()
            k+=1
        else:
            time += A[i]
            if time >K:
                print(i+k)
                exit()
            i += 1
    
        
    
print(i+k)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int, input().split())
a = list(map(int, list(input().split())))
b = list(map(int, list(input().split())))
t = 0
c = 0
while c < n+m:
    if len(b) == 0:
        t = t + a[0]
        a.pop(0)
        if t <= k:
            c = c + 1
        else:
            break
    elif len(a) == 0:
        t = t + b[0]
        b.pop(0)
        if t <= k:
            c = c + 1
        else:
            break
    elif a[0] <= b[0] and a[0] <= 1000000000 and b[0] <= 1000000000:
        t = t + a[0]
        a.pop(0)
        if t <= k:
            c = c + 1
        else:
            break
    elif a[0] > b[0] and a[0] <= 1000000000 and b[0] <= 1000000000:
        t = t + b[0]
        b.pop(0)
        if t <= k:
            c = c + 1
        else:
            break
print(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()))
time = 0
count = 0
Acount = 0
Bcount = 0
while time < K:

    if Acount > N - 1 and Bcount > M - 1:
        break
    elif Acount <= N - 1 and Bcount > M - 1:
        if time + A[Acount] <= K:
            time += A[Acount]
            Acount += 1
            count += 1
        else:
            break
    elif Acount > N - 1 and Bcount <= M - 1:
        if time + B[Bcount] <= K:
            time += B[Bcount]
            Bcount += 1
            count += 1
        else:
            break
    else:
        if A[Acount] <= B[Bcount] and time + A[Acount] <= K:
            time += A[Acount]
            Acount += 1
            count += 1
        elif B[Bcount] <= A[Acount] and time + B[Bcount] <= K:
            time += B[Bcount]
            Bcount += 1
            count += 1
        else:
            break


print(count)

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

ans = 0
pile = 0

aq = deque(a)
bq = deque(b)

while(pile <= k):
    if len(aq) == 0 and len(bq) == 0:
        ans += 1
        break

    if len(aq) == 0 and len(bq) != 0:
        pile += bq.popleft()
        ans += 1
        continue

    if len(aq) != 0 and len(bq) == 0:
        pile += aq.popleft()
        ans += 1
        continue

    if aq[0] >= bq[0]:
        pile += bq.popleft()
        ans += 1
        continue

    if aq[0] < bq[0]:
        pile += aq.popleft()
        ans += 1
        continue



print(ans-1)

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

count = 0
for i in range(N + M):
  if len(A) == 0:
    book = B[0]
    B.popleft()
  elif len(B) == 0:
    book = A[0]
    A.popleft()
  else:
    if A[0] <= B[0]:
      book = A[0]
      A.popleft()
    else:
      book = B[0]
      B.popleft()
  
  if K >= book:
    count += 1
    K -= book
  else:
    break

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


for i in range(M):
    A.append(B[i])
    
A.sort()

ans = 0
count = 0

for i in range(N+M):
    if ans + A[i] <= K:
        ans += A[i]
        count += 1
    else:
        break
    
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()))
i, j = 0, 0
time = 0
while time <= k:
    if i >= n and j < m:
        time += B[j]
        j += 1
    elif i < n and j >= m:
        time += A[i]
        i += 1
    elif i < n and j < m:
        if A[i] < B[j]:
            time += A[i]
            i += 1
        else:
            time += B[j]
            j += 1
    else:
        break
if time > k:
    print(i + j - 1)
else:
    print(i + j)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = []
ans = 0
m = 0
C.extend(A)
C.extend(B)
C = sorted(C)
for i in range(len(C)):
    m += C[i]
    if m > K:
        print(ans)
        exit()
    elif m == K:
        print(ans + 1)
        exit()
    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()))
s = 0
a = A[::-1].pop()
b = B[::-1].pop()
for i in range(1,len(A)+len(B)+1):
    if a <= b:
        s+=a
        a = A[::-1].pop()
    else:
        s+=b
        b = B[::-1].pop()
    if s >= K and i==1:
        print(0)
        break
    if s >= K or i==len(A)+len(B)+1:
        print(i-1)
        break

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()))
aa=[0]*n
ba=[0]*m
aa[0]=a[0]
for i in range(1,n):
  aa[i]=aa[i-1]+a[i]
for i in range(1,m):
  ba[i]=ba[i-1]+b[i]
aa=[0]+aa
ba=[0]+ba
import bisect as bi
ax=bi.bisect_right(aa,k)-1
ans=0
for i in range(ax):
  kk=k-aa[ax-i]
  bx=bi.bisect_right(ba,kk)-1
  t=ax+bx-i
  ans=max(ans,t)
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,K = map(int,input().split())
A = list(map(int,input().split())) #using a
B = list(map(int,input().split())) #using b

a=0
b=0
ans = 0

while K>0:
    if (a == len(A) and b == len(B)):
        ans+=1
        break
    elif  (a == len(A)):
        K-=B[b]
        b+=1
        ans+=1
    elif(b == len(B)):
        K-=A[a]
        a+=1
        ans+=1
    else:
        if A[a]<=B[b]:
            K-=A[a]
            a+=1
            ans+=1
        else:
            K-= B[b]
            b+=1
            ans+=1
if (K<0):
    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()))

book_a = a.pop(0)
book_b = b.pop(0)
time = 0
ans = 0

for _ in range(n+m):
  if k >= time:
    if book_a < book_b:
      ans += 1
      time += book_a
      if a != []:
        book_a = a.pop(0)
      else:
        book_a = 10**9+1
    else:
      ans += 1
      time += book_b
      if b != []:
        book_b = b.pop(0)
      else:
        book_b = 10**9+1
        
  if k < time:
    ans -= 1
    break

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

import math
import itertools

n,m,k=map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
time = 0
max=len(a)+len(b)
for i in range(max):
    if (len(a) == 0):
        if (time + b[0] <= k):
            time += b[0]
            ans += 1
            b.pop(0)
    elif (len(b) == 0):
        if (time + a[0] <= k):
            time += a[0]
            ans += 1
            a.pop(0)
    else:
        tmp = 0
        isA=True
        if (a[0] < b[0]):
            tmp = a[0]
            isA=True
        else:
            tmp = b[0]
            isA = False
        if (time + tmp <= k):
            time += tmp
            ans += 1
            if (isA):
                a.pop(0)
            else:
                b.pop(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()))
ans = 0
cnt = 0

while K >= 0:
    if A != [] and B != []:
        if A[0] >= B[0]:
            ele = B.pop(0)
            if K - ele < 0:
                cnt -= 1
            K -= ele
            cnt += 1
        else:
            ele = A.pop(0)
            if K - ele < 0:
                cnt -= 1
            K -= ele
            cnt += 1
    
    elif A != []:
        ele = A.pop(0)
        if K - ele < 0:
            cnt -= 1
        K -= ele
        cnt += 1
    
    elif B != []:
        ele = B.pop(0)
        if K - ele < 0:
            cnt -= 1
        K -= ele
        cnt += 1
    
    else:
        break
    print(K)
        
print(cnt)

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

counter=0
sum_min=0
i,j=0,0
flag = True
while i<n and j<m:
    if a[i] <= b[j]:
        sum_min+=a[i]
        i+=1
    else:
        sum_min+=b[j]
        j+=1
    if flag and i==n:
        a[n-1]=10**9+1
        i=n-1
        flag=False
    if flag and j==n:
        b[m-1]=10**9+1
        j=m-1
        flag=False
    if sum_min <= k:
        counter+=1
    elif sum_min > k:
        print(counter)
        break
    # print(i,j)
    # print(sum_min)
else:
    print(counter)
# print(sum_min)

Submission status: Wrong Answer

Solution code:
[n, m, k] = list(map(int, input().split()))
aList = list(map(int, input().split()))
bList = list(map(int, input().split()))
numCount = 0
realVal = 0
fakeVal = 0
aList.append(1E10)
bList.append(1E10)
while True:
    if aList[0]<bList[0]:
        fakeVal += aList.pop(0)
        numCount += 1
    else:
        fakeVal += bList.pop(0)
        numCount += 1
    if not fakeVal>k:
        realVal = fakeVal
    else:
        numCount -= 1
        break
print(numCount)

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)

atop = 0
btop = 0
zikan = 0
satu = 0
while True:
    if a[atop] < b[btop]:
        yomu = a[atop]
        atop += 1
    else:
        yomu = b[btop]
        btop += 1
    if zikan + yomu <= k:
        zikan += yomu
        satu += 1
    else:
        break
print(satu)

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

total = 0
cnt = 0

while total < K:
    
    if A == []:
        total += B.pop(0)
    elif B == []:
        total += A.pop(0)
    elif A[0] > B[0]:
        total += A.pop(0)
    else:
        total += B.pop(0)
    cnt += 1

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

count = 0

while K > 0:
    if A == [] and B == []:
        break
    elif not A:
        flag = B
    elif not B:
        flag = A
    elif A[0] <= B[0]:
        flag = A
    else:
        flag = B
    if flag == A:
        K = K - A[0]
        A = A[1:]
        count += 1
    else:
        K = K - B[0]
        B = B[1:]
        count += 1
    if K < 0:
        count -= 1

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

ni = 0
mi = 0
ans = 0
cnt = 0

for i in range(n+m):
  if n == ni and m == mi:
    break
  elif n == ni:
    ans += b[mi]
    mi += 1
  elif m == mi:
    ans += a[ni]
    ni += 1
  elif a[ni] <= b[mi]:
    ans += a[ni]
    ni += 1
  else:
    ans += b[mi]
    mi += 1

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

print(cnt)

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

A_que = deque(A)
B_que = deque(B)

for _ in range(N+M):
    if A_que.__len__() != 0:
        a = A_que[0]
    else:
        a = float('inf')
    if B_que.__len__() != 0:
        b = B_que[0]
    else:
        b = float('inf')
    if A_que.__len__() == 0 and B_que.__len__() == 0:
        break

    if a >= b and K - b >= 0:
        K -= B_que.popleft()
        ans += 1
    elif b > a and K - a >= 0:
        K -= A_que.popleft()
        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()))

cntTime = 0 
result = 0
while True:
    if len(A) != 0 and len(B) != 0:
        if A[0] >= B[0]:
            cntTime += B[0]
            result += 1
            del B[0]   
        else:
            cntTime += A[0]
            del A[0]
            result += 1
        if cntTime > K:
            result -= 1
            break
    elif len(A) == 0 and len(B) == 0:
        break
    else:
        if len(A) == 0 and len(B) != 0:
            cntTime += B[0]
            result += 1
            del B[0]
        elif len(B) == 0 and len(A) != 0:
            cntTime += A[0]
            result += 1
            del A[0]
        if cntTime > K:
            result -= 1
            break
print(result)

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
time=0
while(1):
    if len(a)==0 and len(b)==0:
        print(ans)
        exit()
    else:
        if len(a)==0:
            time+=b[0]
            del b[0]
        elif len(b)==0:
            time+=a[0]
            del a[0]
        else:
            if a[0]>b[0]:
                time+=b[0]
                del b[0]
            elif a[0]<b[0]:
                time+=a[0]
                del a[0]
            else:
                for i in range(min(len(a),len(b))):
                    if a[i]>b[i]:
                        time+=b[0]
                        del b[0]
                        break
                    elif a[i]<b[i]:
                        time+=a[0]
                        del a[0]
                        break
                time+=a[0]
                del a[0]
                        
    if time>k:
        print(ans)
        exit()
    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()))

time = 0
cnt = 0
while time <= k:
    if A!=[] and B!=[]:
        if A[0] <= B[0]:
            time += A.pop(0)
        else:
            time += B.pop(0)
    elif A!=[] and B==[]:
        time += A.pop(0)
    elif A==[] and B!=[]:
        time += B.pop(0)
    else:
        break
    cnt += 1
if time <= k:
    print(cnt)
else:
    print(cnt-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(K)
B.append(K)

index_A=0
index_B=0
time = 0
flag =0
while(time<=K):
  if(A[index_A] == B[index_B]):
    if(A[index_A]==K):
      index_A += 1
      break
    elif(A[index_A+1] < B[index_B+1]):
      time += A[index_A]
      index_A += 1
      flag = 0
    else:
      time += B[index_B]
      index_B += 1
      flag = 1
  elif(A[index_A] > B[index_B]):
    time+= B[index_B]
    index_B += 1
    flag = 1
  else: 
    time += A[index_A]
    index_A += 1
    flag = 0
print(index_A+index_B-1)

Submission status: Wrong Answer

Solution code:
N,M,K = input().split()
N= int(N)
M=int(M)
K=int(K)
A = list(map(int,input().split()))
B = list(map(int,input().split()))
time = 0
count = 0
ai = 0
bi = 0

while (time < K):
    if ai < N and bi < M:
        if A[ai] <= B[bi]:
            time += A[ai]
            count += 1
            ai += 1
        else :
            time += B[bi]
            count += 1
            bi += 1
    else:
        if ai == N and bi != M:
            time += B[bi]
            count+=1
            bi+=1
        else:
            if ai != N and bi == M:
                time += A[ai]
                count += 1
                ai += 1
            else :
                break

if time <= K:
    print(count)

else:
    print(count-1)

Submission status: Wrong Answer

Solution code:
# import sys
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))
sum_t = 0
cumsumA = [0]
cumsumB = [0]
ansA = N
ansB = M
tmp = 0
for i in range(1, N+1):
    tmp = tmp + A[i]
    if tmp > K:
        ansA = i-1
        break
    cumsumA += [tmp]
tmp = 0
for i in range(1, M+1):
    tmp = tmp + B[i]
    if tmp > K:
        ansB = i-1
        break
    cumsumB += [tmp]

ans_t = cumsumA[ansA] + cumsumB[ansB]
ansAA = ansA
ansBB = ansB
ans = ansA + ansB
while K < ans_t:
    ai, bi = A[ansA], B[ansB]
    if ai >= bi:
        ans_t -= ai
        ans -= 1
        ansA -= 1
    else:
        ans_t -= bi
        ans -= 1
        ansB -= 1
print(max([ans, ansAA, ansBB]))
# print(ansA, ansB)

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()))
count = 0
ans = 0
while len(a) != 0 or len(b) != 0:
    if len(a) != 0 and len(b) != 0:
        if a[0] > b[0]:
            ans += b[0]
            b.popleft()
            count += 1
        else:
            ans += a[0]
            a.popleft()
            count += 1
    elif len(a) != 0:
        ans += a[0]
        a.popleft()
        count += 1
    elif len(b) != 0:
        ans += b[0]
        b.popleft()
        count += 1
    if ans > k:
        print(count - 1)
        exit()
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()))

s=0
ac=0
bc=0

for i in range(n):
  s=s+a[i]
  ac=ac+1
  if s > k:
    s=s-a[i]
    ac=ac-1
    break
for i in range(m):
  s=s+b[i]
  bc=bc+1
  if s > k:
    s=s-b[i]
    bc=bc-1
    break

print(ac)
print(bc)

Submission status: Wrong Answer

Solution code:
a,b,c = map(int,input().split())
z = list(map(int,input().split()))
x = list(map(int,input().split()))
if c>=sum(z)+ sum(x):
	print(a+b)
else:
	i,j,q,r=0,0,0,0
	while q<=c and i+j<=(a+b):
		if i<=(a-1) and j<=(b-1):
			if z[i]<=x[j]:
				q+=z[i]
				i+=1
			else:
				q+=x[j]
				j+=1
		else:
			if j==b:
				q+=z[i]
				i+=1
			if i==a:
				q+=x[j]
				j+=1
		r+=1
	print(r-1)

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,B = deque(A),deque(B)
time,ans = 0,0
while A or B:
  if not A: v = B.popleft()
  elif not B: v = A.popleft()
  elif A[0] <= B[0]: v = A.popleft()
  else: v = B.popleft()
  if time + v > k: break
  time += v
  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()))

T=0
U=0
V=0
Q=0
for i in range(N+M):
    if U<N and V<M:
        if A[U]>B[V] and T+B[V]<=K:
            T+=B[V]
            V+=1
            Q+=1
        elif A[U]<=B[V] and T+A[U]<=K:
            T+=A[U]
            U+=1
            Q+=1
    elif U>=N and V<M:
        if T+B[V]<=K:
            T+=B[V]
            V+=1
            Q+=1
    elif U<N and V>=M:
        if T+A[U]<=K:
            T+=A[U]
            U+=1
            Q+=1
    else:
        break

print(Q)

Submission status: Wrong Answer

Solution code:
from collections import deque
N, M, K = map(int,input().split())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))
al = deque(al)
bl = deque(bl)

time = 0
cnt = 0
while time <= K :
    if len(al) == len(bl) == 0:
        break
    if len(al) >= 1 and len(bl) >= 1:
        if al[0] <= bl[0]:
            time += al[0]
            al.popleft()
        else:
            time += bl[0]
            bl.popleft()
    elif len(al) >= 1:
        time += al[0]
        al.popleft()
    elif len(bl) >= 1:
        time += bl[0]
        bl.popleft()
    else:
        pass
    cnt += 1

if len(al) == len(bl) == 0:
    print(N + M)
else:
    print(cnt-1)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a = []
aa = 0
bb = 0
b = []
flag = 0
for i in range(N):
    aa += A[i]
    a.append(aa)
for i in range(M):
    bb += B[i]
    b.append(bb)
MAX = 0
for i in range(N):
    t = a[i]
    if t > K:
        break
    else:
        tt = K-t
        index = bisect_left(b,tt)
        if index == M:
            MAX = max(MAX,i+1+M)
        elif b[index] == tt:
            flag = 1
        else:
            flag = 0
        MAX = max(MAX,i+1+flag+index)

        
print(MAX)

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 = 0
ans = 0
for i in range(N + M):
  
  if len(A) == 0 and len(B) == 0:
    break
  elif len(A) == 0:
    time = time + B[0]
    B.pop(0)
  elif len(B) == 0:
    time = time + A[0]
    A.pop(0)
  else:
    if A[0] < B[0]:
      time = time + A[0]
      A.pop(0)
    else:
      time = time + B[0]
      B.pop(0)
  
  if K < time:
    break
    
  ans = ans + 1
    
print(ans)

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

dp = [[0] * (M + 1) for _ in range(N + 1)]
  
res = 0

for i in range(1, N + 1):
  dp[i][0] = dp[i - 1][0] + A[-i]
  if dp[i][0] <= K:
    res = max(res, i)
  else:
    break

for j in range(1, M + 1):
  dp[0][j] = dp[0][j - 1] + B[-j]
  if dp[0][j] <= K:
    res = max(res, j)
  else:
    break

for i in range(1, N + 1):
  for j in range(1, M + 1):
    dp[i][j] = min(dp[i - 1][j] + A[-i], dp[i][j - 1] + B[-j])
    if dp[i][j] <= K:
      res = max(res, i + j)
    else:
      break

print(res)

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

count = 0
ans = 0
la = len(a)
lb = len(b)
l = la + lb
ac = 0
bc = 0

while k >= count and l > ans:
    if la > ac and lb > bc:
        if k >= count + min(a[0], b[0]):
            count += min(a[0], b[0])
            ans += 1
            if b[0] >= a[0]:
                a.popleft()
                ac += 1
            else:
                b.popleft()
                bc += 1
        else:
            break
    elif la == ac and lb > bc:
        if k >= count + b[0]:
            count += b[0]
            ans += 1
            b.popleft()
            bc += 1
        else:
            break
    elif lb == bc and la > ac:
        if k >= count + a[0]:
            count += a[0]
            ans += 1
            a.popleft()
            ac += 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()))
a = A[0]
if A[0]<= K:
    max = 1
else:
    max = 0
for i in range(1,N):
    a += A[i]
    A[i] = a
    if a <= K:
        max = i+1
b = B[0]
if max >= 1:
    L = K-A[max-1]
else:
    L = K
if B[0]<= L:
    m = 1
else:
    m = 0
for i in range(1,M):
    b += B[i]
    B[i] = b
    if b <= L:
        m = i+1
ans = max+m
if max ==0 and m == 0:
    print(0)
else:
    while(max > 0 and m<M):
        max -= 1
        L = K-A[max-1]
        if m == 0:
            if B[0] <= L:
                m = 1
        if m >= 1:
            while(m<=M and B[m-1]<=L):
                m += 1
        if max + m > ans:
            ans = max+m
    print(ans)

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()))
at=[0]
bt=[]
temp=0
for i in a:
    temp+=i
    at.append(temp)
temp=0
for i in b:
    temp+=i
    bt.append(temp)
ans=0
for i in range(len(at)):
    if at[1]>k and bt[0]>k:
        break
    ind= bisect.bisect_right(bt,k-at[i])
    ans= max(ans, ind+i)
print(ans)

Submission status: Wrong Answer

Solution code:
# import sys
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))
sum_t = 0
cumsumA = [0]
cumsumB = [0]
ansA = N
ansB = M
tmp = 0
for i in range(1, N+1):
    tmp = tmp + A[i]
    if tmp > K:
        ansA = i-1
        break
    cumsumA += [tmp]
tmp = 0
for i in range(1, M+1):
    tmp = tmp + B[i]
    if tmp > K:
        ansB = i-1
        break
    cumsumB += [tmp]

ans_t = cumsumA[ansA] + cumsumB[ansB]
ansAA = ansA
ansBB = ansB
ans = ansA + ansB
while K < ans_t:
    ai, bi = A[ansA], B[ansB]
    if ai >= bi:
        ans_t -= ai
        ans -= 1
        ansA -= 1
    else:
        ans_t -= bi
        ans -= 1
        ansB -= 1
print(max([ans, ansA, ansB]))
# print(ansA, ansB)

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

a.append(10**10)
b.append(10**10)

ara=np.array(a)
arb=np.array(b)
la=np.cumsum(ara)
lb=np.cumsum(arb)

ans=0

i=0
while la[i]<=k:
    rest=k-la[i]
    j=np.searchsorted(lb,rest,side="right")
    ans=max(i+1+j,ans)
    i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from collections import Counter

# N = int(input()) # 1行, 単数
# arg = list(map(int, input().split())) # 1行, 配列
# D = Counter(arg) # 出現数カウント

# print('Yes')
# print('No')
# print()

# while True:
  # try:
    # listA=list(map(int,input().split()))
    # listA.append(list(map(int,input().split())))
  # except:
    # break;

N,M,K = list(map(int, input().split())) # 1行, 配列

A = list(map(int, input().split())) # 1行, 配列
B = list(map(int, input().split())) # 1行, 配列

ans = 0
now = 0
ai = 0
bi = 0
while True:

  if len(A) == ai  and len(B) == bi :
    break
  if len(A) == ai:
    now = now + B[bi]
    bi = bi + 1
  elif len(B) == bi:
      now = now + A[ai]
      ai = ai + 1
  elif len(A) > ai  and len(B) > bi :
    if A[ai] > B[bi]:
      now = now + B[bi]
      bi = bi +1
    else:
      now = now + A[ai]
      ai = ai + 1
  ans = ans + 1
  if now > K:
    ans = ans - 1
    break;
  elif now == K:
    break;

print(ans)