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

a.reverse()
b.reverse()

ans = 0
time = 0

while time <= k:
    if len(a) == 0 and len(b) == 0:
        break
    taken = False
    if len(a) == 0:
        if time+b[-1] <= k:
            time += b.pop()
            taken = True
    elif len(b) == 0:
        if time+a[-1] <= k:
            time += a.pop()
            taken = True
    elif a[-1] <= b[-1]:
        if time+a[-1] <= k:
            time += a.pop()
            taken = True
    else:
        if time+b[-1] <= k:
            time += b.pop()
            taken = True
    if not taken:
        break
    ans += 1

print(ans)

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:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cnt = 0
cost = 0
for i, x in enumerate(a):
    cost += x
    if cost > k:
        cnt = i
        cost -= x
        break
else:
    for j, y in enumerate(b):
        cost += y
        if cost > k:
            cnt = n + j
            cost -= y
            break
    else:
        cnt = n + m

if cnt <= n:
    i, j = cnt, 0
else:
    i, j = n, cnt - n + 1

ans = cnt
initial = True
while i >= 0 and j < m:
    if i < n and not initial:
        cost -= a[i]
        cnt -= 1
    while cost + b[j] <= k and j < m - 1:
        j += 1
        cnt += 1
        cost += b[j]
    ans = max(cnt, ans)
    i -= 1
    if initial: initial = False

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
t=[]
if sum(a)+sum(b)<=k:
    c=n+m
elif a[0]==1000000000 and b[0]==1000000000:
    c=1
elif a[0]>1000000000:
    while k>=b[0]:
        k-=b[0]
        b=b[1:]
        c+=1
elif b[0]>1000000000:
    while k>=a[0]:
        k-=a[0]
        a=a[1:]
        c+=1
else:
    for u in range(n):
        for r in range(m):
            if sum(a[:u])+sum(b[:r])<=k:
                t.append(u+r+2)
    c=min(t)
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()))
countNum = 0
countNumTemp = countNum
countTime = 0
countTimeTemp = countTime
loopNum = max(N,M)
while countTimeTemp <= K:
    countTime = countTimeTemp
    countNum = countNumTemp
    try:
        if A[0] < B[0]:
            countTimeTemp += A.pop(0)
            countNumTemp += 1
        else:
            countTimeTemp += B.pop(0)
            countNumTemp += 1
    except:
        if len(A) != 0:
            countTimeTemp += A.pop(0)
            countNumTemp += 1
        elif len(B) != 0:
            countTimeTemp += B.pop(0)
            countNumTemp += 1
        else:
            break
print(countNum)

Submission status: Wrong Answer

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

i, j = 0, 0
suma, sumb = 0, 0
flaga, flagb = True, True

while True:
    if i < len(a):
        if k - suma >= a[i]:
            suma += a[i]
            i += 1
        else:
            flaga = False
    else:
        flaga = False

    if j < len(b):
        if k - sumb >= b[j]:
            sumb += b[j]
            j += 1
        else:
            flagb = False
    else:
        flagb = False
    if not flaga:
        if not flagb:
            break

p = max(i, j)
q = min(i, j)

br = False
maxbooks = 0
for x in range(p-1, -1, -1):
    for y in range(q-1, -1, -1):
        if sum(a[0:x+1]) + sum(b[0:y+1]) <= k:
            books = x + y + 2
            maxbooks = max(maxbooks, books)
            br = True
            break
    if br:
        break
print(maxbooks)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate as ia 
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = list(ia(A))
b = list(ia(B))
na = 0
nb = 0
for i in a:
  if i <= K:
    na += 1
  else:
    break
for i in b:
  if i <= K:
    nb += 1
  else:
    break
print(na, nb)
t = a[na-1]
for i in B:
  if t + i > K:
    break
  else:
    na += 1
    t += i
t = b[nb-1]
for i in A:
  if t + i > K:
    break
  else:
    nb += 1
    t += i
print(max(na, nb))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

acc1 = list(accumulate(A))
acc2 = list(accumulate(B))

def is_ok(a, b):
    if acc1[a] + acc2[b] <= K:  return 1
    return 0

def binary_search(i, left, right):
    while (abs(right - left) > 1):
        mid = (left + right) // 2
        if is_ok(i, mid):  right = mid
        else:  left = mid
    return right

ans = 0
for i in range(N):
    ret = binary_search(i, M, -1)
    if ret == -1:  
      if acc1[i] <= K:  ans = max(i + 1, ans)
    else:
      ans = max(ans,  i + ret + 2)
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_i = 0
b_i = 0

result = 0
time = 0

while True:
    if a_i >= n and b_i >= m:
        break
    elif a_i >= n:
        if time + b[b_i] <= k:
            time += b[b_i]
            result += 1
            b_i += 1
            continue
        else:
            break
    elif b_i >= m:
        if time + a[a_i] <= k:
            time += a[a_i]
            result += 1
            a_i += 1
            continue
        else:
            break
    elif a[a_i] <= b[b_i]:
        if time + a[a_i] <= k:
            time += a[a_i]
            result += 1
            a_i += 1
            continue
        else:
            break
    else:
        if time + b[b_i] <= k:
            time += b[b_i]
            result += 1
            b_i += 1
            continue
        else:
            break

print(result)

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()))
sum_A=0
count_A=0
sum_B=0
count_B=0
ans=0

for i in range(N):
  temp_A=A[i]
  if sum_A+temp_A<K:
    sum_A += temp_A
  else:
    if i>0:
      count_A = i
      break
    else:
      break
else:
  count_A = i+1

for i in range(M):
  temp_B=B[i]
  if sum_B+temp_B<K:
    sum_B += temp_B
  else:
    if i>0:
      count_B = i
      break
    else:
      break
else:
  count_B = i+1
  
def check(K,sum_A,sum_B,count_A,count_B):
  if sum_A+sum_B<=K:
    return count_A+count_B
  else:
    return 0

if max(sum_A,sum_B)==0:
  pass
else:
  ans = check(K,sum_A,sum_B,count_A,count_B)

while True:
  if ans>0:
    break
  if count_A==0 and count_B==0:
    break
  elif count_A==0:
    sum_B-=B[count_B-1]
    count_B-=1
    ans = check(K,sum_A,sum_B,count_A,count_B)
  elif count_B==0:
    sum_A-=A[count_A-1]
    count_A-=1
    ans = check(K,sum_A,sum_B,count_A,count_B)
  if A[count_A-1] > B[count_B-1]:
    sum_A-=A[count_A-1]
    count_A-=1
    ans = check(K,sum_A,sum_B,count_A,count_B)
  else:
    sum_B-=B[count_B-1]
    count_B-=1
    ans = check(K,sum_A,sum_B,count_A,count_B)
  
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
from decimal import *
n,m,k = [Decimal(int(e)) for e in input().split()]
As = deque([Decimal(int(e)) for e in input().split()])
Bs = deque([Decimal(int(e)) for e in input().split()])
result = 0
while True:
    if (not As) and (not Bs):
        break
        
    if (not As) and (Bs[0]>k):
        break
    if (not As) and (Bs[0]<=k):
        k = k-Bs.popleft()
        result = result + 1
        continue
        
    if (not Bs) and (As[0]>k):
        break
    if (not Bs) and (As[0]<=k):
        k = k-As.popleft()
        result = result + 1
        continue
    
    
    if As[0] <= Bs[0]:
        min_reduce = As.popleft()
    else:
        min_reduce = Bs.popleft()

    if min_reduce > k:
        break
    else:
        k = k-min_reduce
        result = result + 1
print(result)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
A_list = [0] + list(map(int,input().split()))
B_list = [0] + list(map(int,input().split()))
count = 0
output = 0
for i in range(N + 1):
    count += A_list[i]
    if count > K:
        break
for j in range(i + 1 + 1):
    alcount = sum(A_list[:j + 1])
    for h in range(M):
        alcount += B_list[h]
        if alcount > K:
            break
        if j + h + 2 > output:
            output = j + h + 2
print(output -2)

Submission status: Wrong Answer

Solution code:

N,M,K = map(int,input().split())
A_lis = list(map(int,input().split()))
B_lis = list(map(int,input().split()))





if A_lis[0]>B_lis[0]:
    status=B_lis[0]
elif  A_lis[0]<B_lis[0]:
    status=A_lis[0]
else:
    status=A_lis[0]
    
    

count=0



for i in range(len(A_lis)+len(B_lis)):
    if K>status:
        if len(A_lis)>0 and len(B_lis)>0:
            if A_lis[0]<B_lis[0]:
                pd=A_lis.pop(0)
                status+=pd
                count+=1
            elif A_lis[0]>B_lis[0]:
                pd=B_lis.pop(0)
                status+=pd
                count+=1
            elif A_lis[0]==B_lis[0]:
                pd=A_lis.pop(0)
                status+=pd
                count+=1
        elif len(A_lis)==0:
            pd=B_lis.pop(0)
            status+=pd
            count+=1
        elif len(B_lis)==0:
            pd=A_lis.pop(0)
            status+=pd
print(str(count))

Submission status: Wrong Answer

Solution code:
an,bm,khun = map(int,input().split())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))
count = 0
alist.append(khun+1)
blist.append(khun+1)
alist.reverse()
blist.reverse()
for i in range(an+bm):
    if alist[-1]<=blist[-1] and khun >=alist[-1]:
        khun -= alist[-1]
        count += 1
        alist.pop(-1)
    elif khun >= blist[-1]:
        khun -= blist[-1]
        count += 1
        blist.pop(-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()))

count = 0
time = 0
i = 0
j = 0
while True:
   if (not a) and (not b):
      break
   elif a and not b:
      time+= a.pop(0)
   elif b and not a:
      time+=b.pop(0)
   else:
      if a[0] > b[0]:
         time+=b.pop(0)
      else:
         time+=a.pop(0)
   if time > k:
      break
   else:
      count+=1
print(count)

Submission status: Wrong Answer

Solution code:
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
import math
from decimal import *
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
sum = 0
acount = 0
bcount = 0

while(sum < k):
    if acount == len(a) and bcount == len(b):
        break

    elif acount == len(a):
        mi = b[bcount]
        sum = Decimal(sum) + Decimal(mi)
        ans += 1
        bcount += 1

    elif bcount == len(b):
        mi = a[acount]
        sum = Decimal(sum) + Decimal(mi)
        ans += 1
        acount += 1

    else:
        if a[acount] < b[bcount]:
            mi = a[acount]
            sum = Decimal(sum) + Decimal(mi)
            ans += 1
            acount += 1
        else:
            mi = b[bcount]
            sum = Decimal(sum) + Decimal(mi)
            ans += 1
            bcount += 1

if k < sum:
    print(ans - 1)
else:
    print(ans)

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)
#print(a,b)
num = 0
cnt = 0

L = []
while a and b:
    if a[0] <=b[0]:
        L.append(a[0])
        a.popleft()
    else:
        L.append(b[0])
        b.popleft()
if a:
    for i in range(len(a)):
        L.append(a[i])
if b:
    for i in range(len(b)):
        L.append(b[i])
#print(L,a,b)
for i in range(len(L)):
    num +=L[i]
    #print(num)
    if num >k:
        print(i)
        exit()
    elif num == k:
        print(i+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()))

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

ans = 0
ai = 0
bi = 0
time = k
while True:
  if A[ai] != -1 and B[bi] != -1:
    if A[ai] <= B[bi] and time >= A[ai]:
      time -= A[ai]
      ans += 1
      ai += 1
    elif A[ai] > B[bi] and time >= B[bi]:
      time -= B[bi]
      ans += 1
      bi += 1
    else:
      break
  elif A[ai] != -1:
    if time >= A[ai]:
      time -= A[ai]
      ans += 1
      ai += 1
    else:
      break
  elif B[bi] != -1:
    if time >= B[bi]:
      time -= B[bi]
      ans += 1
      bi += 1
    else:
      break
  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()))
i, j, ans = 0, 0, 0
while k > 0:
    if i < n and j < m:
        if a[i] < b[j]:
            k -= a[i]
            i += 1
        else:
            k -= b[j]
            j += 1
    elif i < n and j == m:
        k -= a[i]
        i += 1
    elif i == n and j < m:
        k -= b[j]
        j += 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()))
c = 0
a = a[::-1]
b = b[::-1]
a_i = n-1
b_i = m-1
t = 0
while t+min(a[a_i], b[b_i]) <= k:
    if a_i < 0 and b_i >= 0:
        if t+b[b_i] <= k:
            c += 1
            t += b[b_i]
            b_i -= 1
    elif b_i < 0 and a_i >= 0:
        if t+a[a_i] <= k:
            c += 1
            t += a[a_i]
            a_i -= 1
    elif a_i < 0 and b_i < 0:
        break
    elif a[a_i] < b[b_i]:
        c += 1
        t += a[a_i]
        a_i -= 1
    elif a[a_i] > b[b_i]:
        c += 1
        t += b[b_i]
        b_i -= 1
    else:
        break

print(c)

Submission status: Wrong Answer

Solution code:
import copy
N,M,K = map(int,input().split())
A = [0]*N
B = [0]*M
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a = 0
b = 0

tmp = 0
ans = 0
# for i in range(200000):
#     if A[a] < B[b]:
#         if tmp <= K:
#             tmp += A[a]
#             ans += 1
#             a += 1
#     elif A[a] > B[b]:
#         if tmp <= K:
#             tmp += B[b]
#             ans += 1
#             b += 1
#     if a > len(A)-1 or b > len(B)-1:
#         break
fa = False
fb = False

while len(A) > 0 or len(B) > 0:
    AA = copy.copy(A)
    BB = copy.copy(B)
    if len(AA) != 0:
        a = AA.pop(0)
        fa = True
    if len(BB) != 0:
        b = BB.pop(0)
        fb = True
    if fa and fb:
        if a<=b:
            tmp += a
            ans += 1
            A = AA
        else:
            tmp += b
            ans += 1
            B = BB
    else:
        if fa:
            tmp += a
            ans += 1
            A = AA
        if fb:
            tmp += b
            ans += 1
            B = BB

    if tmp >= K:
        break
    fa = False
    fb = False
    
    #print(tmp,A,B)
    
if len(A)==0 and len(B)==0:
    print(ans)
else:
    print(ans-1)

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

for n in range(N+M):
    if not A and not B:
        break
    elif not A:
        K = K - B.popleft()
    elif not B:
        K = K - A.popleft()
    elif A[0] <= B[0]:
        K = K - A.popleft()
    elif B[0] < A[0]:
        K = K - B.popleft()

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

print(k)

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

sumA = [A[0]]
sumB = [B[0]]
maxA = -1
maxB = -1

ans = 0

for i in range(N-1):
    if sumA[-1] + A[i+1] <= K:
        sumA.append(sumA[-1] + A[i+1])
        maxA = i+1
    else:
        break

for i in range(M-1):
    if sumB[-1] + B[i+1] <= K:
        sumB.append(sumB[-1] + B[i+1])
        maxB = i+1
    else:
        break

ans = max(maxA + 1, maxB + 1)

for i in range(len(sumB)):
    if sumA[maxA] + sumB[i] <= K:
        ans = max(ans, maxA+1 + i + 1)
    else:
        break

for i in range(len(sumA)):
    if sumB[maxB] + sumA[i] <= K:
        ans = max(ans, maxB + 1 + i + 1)
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K=[int(N) for N in input().split()]
A=[int(A) for A in input().split()]
B=[int(B) for B in input().split()]
p=0
if K>=(sum(A)+sum(B)):
    print(len(A)+len(B))
else:
    while K>=0:
        try:
            if A[0]>B[0]:
                K-=B[0]
                p+=1
                del B[0]
            else:
                K-=A[0]
                p+=1
                del A[0]
        except:
            try:
                K-=B[0]
                p+=1
                del B[0]
            except:
                K-=A[0]
                p+=1
                del A[0]
    print(p-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()))
cnt=0
temp=0
Ai=0
Bi=0
for i in range(n+m):
  if Ai==n and Bi==m:
    break;
  elif Ai==n and Bi<m:
    if temp+B[Bi]<=k:
      temp+=B[Bi]
      cnt+=1
      Bi+=1
    else:
      break;
  elif Bi==m and Ai<n:
    if temp+A[Ai]<=k:
      temp+=A[Ai]
      cnt+=1
      Ai+=1
    else:
      break;
  elif Ai<n and Bi<m:
    if A[Ai]<=B[Bi]:
      if temp+A[Ai]<=k:
        temp+=A[Ai]
        cnt+=1
        Ai+=1
      else:
        break;
    elif A[Ai]>B[Bi]:
      if temp+B[Bi]<=k:
        temp+=B[Bi]
        cnt+=1
        Bi+=1
      else:
        break;
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()))

p_time = 0
time = 0
while time < k:
    if len(a) > 0 and len(b) > 0:
        if a[0] <= b[0]:
            time += a[0]
            a.remove(a[0])
        else:
            time += b[0]
            b.remove(b[0])
    elif len(a) <= 0 and len(b) <= 0:
        break
    elif len(a) <= 0 < len(b):
        time += b[0]
        b.remove(b[0])
    elif len(b) <= 0 < len(a):
        time += a[0]
        a.remove(a[0])
    if time <= k:
        p_time += 1

print(p_time)

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(-1)
B.append(-1)

ans = 0
ai = 0
bi = 0
time = k
while True:
  print(time, ai, bi)
  if A[ai] != -1 and B[bi] != -1:
    if A[ai] <= B[bi] and time >= A[ai]:
      time -= A[ai]
      ans += 1
      ai += 1
    elif A[ai] > B[bi] and time >= B[bi]:
      time -= B[bi]
      ans += 1
      bi += 1
    else:
      break
  elif A[ai] != -1:
    if time >= A[ai]:
      time -= A[ai]
      ans += 1
      ai += 1
    else:
      break
  elif B[bi] != -1:
    if time >= B[bi]:
      time -= B[bi]
      ans += 1
      bi += 1
    else:
      break
  else:
    break

print(ans)

Submission status: Wrong Answer

Solution code:
# AtCoder
from collections import deque
N, M, K = map(int, input().split())
A = deque(map(int, input().split()))
B = deque(map(int, input().split()))

ans = 0
count = 0
while True:
    if len(A) != 0 and len(B) != 0:
        if A[0] > B[0]:
            t = B.popleft()
        else:
            t = A.popleft()
    elif len(A) == 0 and len(B) != 0:
        t = B.popleft()
    elif len(B) == 0 and len(A) != 0:
        t = A.popleft()

    count += t
    if 0 > K - count:
        break
    elif K - count == 0:
        ans += 1
        break
    elif K - count > 0:
        pass

    ans += 1

print(ans)

Submission status: Wrong Answer

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

minute=0
books=0
an=a.pop(0)
bn=b.pop(0)

while root[0] + root[1] > books and minute < root[2]:
    if an < bn:
        minute += an
        books += 1
        if len(a) != 0:
            an = a.pop(0)
        else:
            an = 1000000000
    elif bn < an:
        minute += bn
        books += 1
        if len(b) != 0:
           bn = b.pop(0) 
        else:
            bn = 1000000000
    else:
        minute += an
        books += 1
        if len(a) != 0:
            an = a.pop(0)
        elif len(b) != 0:
           bn = b.pop(0) 
        else:
            pass

if minute > root[2]:
    print(books-1)
else:
    print(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()))
t = 0
a_i = 0
b_i = 0
while(t <= k):
  if(10**9 < t):
    break
  if(a_i < len(a) and t + a[a_i] < 10**9 and (b_i == len(b) or a[a_i] <= b[b_i])):
    t += a[a_i]
    a_i += 1
  elif(b_i < len(b) and t + b[b_i] < 10**9 and (a_i == len(a) or b[b_i] < a[a_i])):
    t += b[b_i]
    b_i += 1
  else:
    break
print(a_i + b_i)

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

    T = []
    TA = []
    C = []

    if A[0] > B[0]:
        A, B = B, A

    for i, a in enumerate(A):
        TA.append(a)
        C.append(i + 1)
        if i != 0:
            TA[i] += TA[i - 1]

        T.append(TA[i])
        if TA[i] > K:
            T[i] -= a
            C[i] -= 1
            break

        for b in B:
            T[i] += b
            C[i] += 1
            if T[i] > K:
                T[i] -= b
                C[i] -= 1
                break

    print(max(C))


if __name__ == '__main__':
    main()

exit()

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_right
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,M,K = map(int, readline().split())
    A = [int(i) for i in readline().split()]
    B = [int(i) for i in readline().split()]

    acc_A = list(accumulate(A))
    acc_B = list(accumulate(B))

    ans = 0
    for i, a in enumerate(acc_A):
        tmp = i + 1
        rest = K - a
        if rest < 0:
            break
        b_ind = bisect_right(acc_B, rest)
        tmp += b_ind

        ans = max(ans, tmp)

    print(ans)
       


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#C問題
N, M, K = map(int,input().split())

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

time = 0
ai = 0
bi = 0
while (time < K):
#  print('ai:',ai)
#  print('bi:',bi)
#  print('time:',time)  
  if (ai < N-1 and bi < M-1): #AにもBにも本がまだ2冊以上のこっているとき
    if (A[ai] + A[ai+1] < B[bi] + B[bi]):
      if(time + A[ai] <= K):
        time += A[ai]
        ai += 1
      else: 
        break
    else: #Bのほうが時間が短い
      if (time + B[bi] <= K):
        time += B[bi]
        bi += 1
      else:
        break
  elif (ai < N and bi < M): #AにもBにも1冊以上本がまだのこっているとき
    if (A[ai] < B[bi]): #Aのほうが時間が短い
      if(time + A[ai] <= K):
        time += A[ai]
        ai += 1
      else: 
        break
    else: #Bのほうが時間が短い
      if (time + B[bi] <= K):
        time += B[bi]
        bi += 1
      else:
        break
  elif (ai == N and bi < M): #Aに本がなくなってBに本があるとき
    if (time + B[bi] <= K):
      time += B[bi]
      bi += 1
    else:
      break
  elif (ai < N and bi == M): #Bに本がなくなってAに本があるとき
    if (time + A[ai] <= K):
      time += A[ai]
      ai += 1
    else:
      break
  else: #AにもBにも本がないとき
    break
  
print(ai+bi)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, m, k = map(int, readline().split())
a = list(map(int, readline().split()))
b = list(map(int, readline().split()))
if sum(a)+sum(b) <= k:
    print(len(a)+len(b))
    exit()

a = a + ([200010] * 3)
b = b + ([200010] * 3)

t = 0
i = 0
j = 0
ans =0
while t < k:
    if a[i] <= b[j]:
        t += a[i]
        i += 1
    elif b[j] < a[i]:
        t += b[j]
        j += 1
    if t <= k:
        ans += 1
    # print(t)
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()))

a = 0
b = 0
ans = 0
S = 0
while a <= N or b <= B:
  if a == N and b == M:
    break
  elif a == N:
    v = B[b]
    b += 1
  elif b == M:
    v = A[a]
    a += 1
  else:
    Va = A[a]
    Vb = B[b]
    if  Va < Vb:
      v = Va
      a += 1
    else:
      v = Vb
      b += 1
  
  S2 = S + v
  if S2 > K:
    a -= 1
    break
  else:
    S = S2
      
print(a+b)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
A, B, t = list(map(int, input().split()))
a = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))
for i in range(1, A):
    a[i] = a[i]+a[i-1]
a_ = np.zeros(A+1)
a_[1:] = a.copy()
for i in range(1, B):
    b[i] = b[i]+b[i-1]
b_ = np.zeros(B+1)
b_[1:] = b.copy()
c = 0
for i in range(1, A+1):
    for j in range(1, B+1):
        if a_[i]+b_[j] <= t:
            if i+j>c:
                c = i+j
        else:
            break
print(c)

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

k_now = 0
satu = 0

if n == 0 and m == 0:
    print(0)
    exit

while k_now < k:
    if bool(a) == False and bool(b) == False:
        break
    if bool(a) == True and bool(b) == False:
        k_now += a.pop(0)
        satu += 1
    elif bool(a) == False and bool(b) == True:
        k_now += b.pop(0)
        satu += 1
    else:
        if a[0] <= b[0]:
            k_now += a.pop(0)
            satu += 1
        else:
            k_now += b.pop(0)
            satu += 1

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()))
C=list()
for i in range(min(N,M)):
  C.append(A[i])
  C.append(B[i])
if N>M:
  C.extend(A[N-M:N])
elif M>N:
  C.extend(B[M-N:M])
  
if min(C[0],C[1])>K:
  print('0')
  exit()
k=0
ans=0
for i in range(len(C)):
  key=min(C[0],C[1])
  k+=key
  ans+=1
  C.remove(key)
  if k>K:
    break
  if len(C)==1:
    k+=C[0]
    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()))

ai =0
bi=0
st =0
c = 0
while True:
  if ai == N:
    if bi == M:
      break
    else:
      st += b[bi]
      if st > K:
        break
      bi += 1
      c +=1
  elif bi == M:
    if ai == N:
      break
    else:
      st += a[ai]
      if st > K:
        break
      ai += 1
      c += 1
  elif a[ai] > b[bi]:
    st += b[bi]
    if st > K:
      break
    bi +=1
    c +=1
  elif a[ai] < b[bi]:
    st += a[ai]
    if st > K:
      break
    ai +=1
    c +=1
  elif a[ai] == b[bi]:
    tmpst = st
    tmpc =0
    tmpai = ai
    tmpbi = bi
    while True:
      tmpst +=a[tmpai]
      if tmpai < N-1:
        tmpai+=1
      if tmpbi < M-1:
        tmpbi+=1
      if tmpst > K:
        st += a[ai]
        if st > K:
          print(c)
          exit()
        ai +=1
        c +=1
        #print(c+tmpc,'ja')
        #exit()
      if a[tmpai] > b[tmpbi]:
          st += a[ai]
          if st > K:
              print(c)
              exit()
          ai += 1
          c += 1
          break
      elif a[tmpai] < b[tmpbi]:
          st += b[bi]
          if st > K:
              print(c)
              exit()
          bi += 1
          c += 1
          break
      if tmpai == N-1 and tmpbi == M-1:
          print(N+M)
          exit()
      #print(tmpst)
      tmpc += 1
#      print(tmpai, tmpbi)
print(c)