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:
import decimal
N, M, K = map(decimal.Decimal, input().split())
Ai=[decimal.Decimal(i) for i in input().split()]
Bi=[decimal.Decimal(i) for i in input().split()]
nbook=decimal.Decimal(0)
tbook=decimal.Decimal(0)
na=0; nb=0

while tbook <K:
    if((na<len(Ai)) and (nb<len(Bi))):
        if(Ai[na]<=Bi[nb]):
            if(decimal.Decimal(tbook)+Ai[na]<=K):
                nbook+=1;  tbook+=Ai[na];na+=1;
            else:
                break;
        else:
            if(decimal.Decimal(tbook)+Bi[nb]<=K):
                nbook+=1;tbook+=Bi[nb]; nb+=1; 
            else:
                break;
    elif( (na>=len(Ai)) and (nb<len(Bi))):
        if(decimal.Decimal(tbook)+Bi[nb]<=K):
            nbook+=1;tbook+=Bi[nb]; nb+=1;
        else:
            break;  
    elif( (na<len(Ai)) and (nb>=len(Bi))):
        if(decimal.Decimal(tbook)+Ai[na]<=K):
            nbook+=1;  tbook+=Ai[na];na+=1;
        else:
            break;
     
    else:
        break;      
print(nbook)

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[::-1]
B = B[::-1]

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

print(cnt - 1)

Submission status: Wrong Answer

Solution code:
n,m,k=(int(x) for x in input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ma = n + m
a.extend(b)
a.sort()

if k < min(a):
  print(0)
  exit()
else:
  pass
list = [0]

for i in range(ma):
  if k >= min(a): 
    k -= a[i]
    list.append(i)
  else:
    break

t = max(list) +1
print(t)

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()))
AB = list()
ai = 0
bi = 0
time = 0
num = 0
leng = N + M
print(leng)
for _ in range(leng):
  if ai == len(A) and bi == len(B):
    break
  elif ai == len(A):
    AB.append(B[bi])
    bi += 1
  elif bi == len(B):
    AB.append(A[ai])
    ai += 1
  elif A[ai] <= B[bi]:
    AB.append(A[ai])
    ai += 1
  else:
    AB.append(B[bi])
    bi += 1
if sum(AB) <= K:
  print(leng)
  sys.exit()
for i in range(leng):
  time += AB[i]
  if time <= K:
    num += 1
  else:
    break
print(num)

Submission status: Wrong Answer

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


ans = 0
ans_time = 0
adex = 0
bdex = 0
c = []
while True:
    if adex < n and bdex < m:
        if a[adex] < b[bdex]:
            ans_time += a[adex]
            c.append(a[adex])
            adex += 1
        else:
            ans_time += b[bdex]
            c.append(b[bdex])
            bdex += 1
        ans += 1
    elif adex >= n and bdex < m:
        ans_time += b[bdex]
        c.append(b[bdex])
        bdex += 1
        ans += 1
    elif adex < n and bdex >= m:
        ans_time += a[adex]
        c.append(a[adex])
        adex += 1
        ans += 1
    else:
        break
        
    #if ans_time > k:
    #    ans -= 1
    #    break


#print(c)
x = 0
i = 0
while i < len(c):
    x += c[i]
    i += 1
    if x > k:
        i -= 1
        break
ans = i

print(max(0,ans))

Submission status: Wrong Answer

Solution code:
import itertools
import bisect

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

cA = list(itertools.accumulate(A))
cB = list(itertools.accumulate(B))

#print(cA)
#print(cB)

ans = 0
for i in range(n):
    tmp = cA[-(i+1)]
    if tmp < k:
        indb = bisect.bisect_right(cB, k - tmp)
        #print(indb)
        ans = max(ans, (n-i)+indb)
    
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()))
all=N+M
maxi=0
maxj=0
cost1=0
cost2=0
for i in range(N):
    if cost1+A[i]<=K:
        cost1+=A[i]
    else:
        maxi=i
        break
else:maxi=N
for j in range(M):
    if cost2+B[j]<=K:
        cost2+=B[j]
    else:
        maxj=j
        break
else:maxj=M
if maxi==N and maxj==M:
    print(N+M)
else:
    if maxi>maxj:
        K-=cost1
        for j in range(M):
            if K-B[j]>=0:
                maxi+=1
                K=K-B[j]
            else:
                print(maxi)
                exit()
    elif maxj>maxi:
        K -= cost2
        for i in range(N):
            if K-A[i]>=0:
                maxj+=1
                K=K-A[i]
            else:
                print(maxj)
                exit()
    elif maxi==maxj:
        k1=K
        k1-=cost1
        for j in range(M):
            if k1-B[j]>=0:
                maxi+=1
                k1-=B[j]
            else:break
        k2=K
        k2-=cost1
        for i in range(N):
            if k2-A[i]>=0:
                maxj+=1
                k2-=A[i]
            else:break
        print(max(maxi,maxj))

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(300000)
b.append(300000)
c = []
e = 0
f = 0
for i in range(len(a)):
    b.append(a[i])
while sum(c) < k:
    if a[e] < b[f]:
        c.append(a[e])
        e += 1
    else:
        c.append(b[f])
        f += 1
if sum(c) == k:
    print(len(c))
else:
    print(len(c)-1)

Submission status: Wrong Answer

Solution code:
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

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

def main():
    n,m,k = readInt()
    a = readInt()
    b = readInt()
    t = 0
    i = 0
    j = 0
    ans = 0
    while t<k:
        if i==n and j==m:
            break
        elif i==n:
            if t+b[j]<=k:
                t += b[j]
                j += 1
                ans += 1
            else:
                break
        elif j==m:
            if t+a[i]<=k:
                t += a[i]
                i += 1
                ans += 1
            else:
                break
        else:
            if t+a[i]>k and t+b[j]>k:
                break
            else:
                if a[i]<=b[j]:
                    t += a[i]
                    i += 1
                else:
                    t += b[j]
                    j += 1
                ans += 1
    print(ans)
    return

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

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

    yomuA = a[0]
    yomuB = b[0]
    ans = []
    
    countA = 0
    countB = 0

    for i in range(n+m):
        if (yomuA < yomuB):
            if (countA < n-1):
                ans.append(yomuA)
                countA += 1
                yomuA = a[countA]
            elif (countA == n-1):
                ans.append(yomuA)
                for j in range(countB, m):
                    ans.append(b[j])
                break
        else:
            if (countB < m-1):
                ans.append(yomuB)
                countB += 1
                yomuB = b[countB]
            elif(countB == m-1):
                ans.append(yomuB)
                for t in range(countA, n):
                    ans.append(a[t])
                break

    sum_ = 0
    for i in range(len(ans)):
        sum_ += ans[i]
        if (sum_ > k):
            print(i)
            break
        elif(i == len(ans)-1):
            print(i+1)

main()

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

inf = pow(10,9)+1
_A = [inf]*N
_B = [inf]*M
if A[0] <= K:
    _A[0] = A[0]
if B[0] <= K:
    _B[0] = B[0]

cnt_a = 0
for i in range(N-1):
    if _A[i]+A[i+1] <= K:
        _A[i+1] = _A[i]+A[i+1]
        cnt_a += 1
    else:
        break

cnt_b = 0     
for i in range(M-1):
    if _B[i]+B[i+1] <= K:
        _B[i+1] = _B[i]+B[i+1]
        cnt_b += 1
    else:
        break

if cnt_a == 0:
    ans = cnt_a+1
else:
    ans = cnt_a+2
final_ans = 0
b = 0
for a in range(cnt_a, -2, -1):
    ans -= 1
    if a != -1:
        time = _A[a]
    else:
        time = 0
    while time <= K:
        if b < len(_B) and _A[a] + _B[b] <= K:
            time = _A[a] + _B[b]
            ans += 1
            b += 1
        else:
            break
    final_ans = max(final_ans, ans)
    
print(final_ans)

Submission status: Wrong Answer

Solution code:
import random
n, m, k = map(int, input().split())
# n, m, k = random.randint(1, 10**5), random.randint(1, 10**5), random.randint(10**8, 10**9)
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
# a_list = [random.randint(1, 10**7) for i in range(n)]
# b_list = [random.randint(1, 10**7) for i in range(m)]
# print(n,m,k)
# print(a_list[0], b_list[0])
a_sum = [0]
b_sum = [0]
max_a = 0
max_b = 0
for i in range(1, max(n+1, m+1)):
    if i < n+1:
        a_sum.append(a_sum[i-1] + a_list[i-1])
        if a_sum[i] < k:
            max_a = i
    if i < m+1:
        b_sum.append(b_sum[i-1] + b_list[i-1])

max_num = max_a
# print(max_a)
while max_a > -1:
    while max_b < m and b_sum[max_b] <= k-a_sum[max_a]:
        max_b += 1
    if max_num < max_a + max_b:
        max_num = max_a + max_b
        print(max_a, max_b)
    max_a -= 1

print(max_num)

Submission status: Wrong Answer

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

book = 0
minute = 0

while minute < k:
    if a:
        if b:
            if a[0] > b[0]:
                minute += b[0]
                book += 1
                if minute > k:
                    book -= 1
                del b[0]
            else:
                minute += a[0]
                book += 1
                if minute > k:
                    book -= 1
                del a[0]
        else:
            minute += a[0]
            book += 1
            if minute > k:
                book -= 1
            del a[0]
    else:
        minute += b[0]
        book += 1
        if minute > k:
            book -= 1
        del b[0]


print(book)

Submission status: Wrong Answer

Solution code:
a = input().split()
x = input().split()
y = input().split()
z = x + y
zz = []
zz = list(map(lambda i: int(i), z))
t = 0
m = 0
for i in range(len(zz)):
  if t > int(a[2]):
    break
  t += sorted(zz)[i]
  m += 1
print(m)

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

t = 0
cnt = 0

i = 0
j = 0

while t <= k and (i < len(a) or j < len(b)):
    if i < len(a) and j >= len(b):
        t += a[i]
        i += 1
    elif j < len(b) and i >= len(a):
        t += b[j]
        j += 1
    elif a[i] < b[j]:
        t += a[i]
        i += 1
    else:
        t += b[j]
        j += 1
    
    if t <= k:
        cnt += 1
        
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()))
L = len(A)+len(B)
for i in range(L):
    if len(A) >0 and len(B)>0:
        if A[0]<B[0]:
            k = k-A[0]
            A.pop(0)
        else:
            k = k-B[0]
            B.pop(0)
    elif len(A) >0 and len(B) == 0:
            k = k-A[0]
            A.pop(0)
    elif len(B) >0 and len(A) == 0:
            k = k-B[0]
            B.pop(0)
    print(k)
    if k<0:
        break
    elif len(A)==0 and len(B)==0:
        i = L
        break

print(i)

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

def calc (a,b):
  ma = len(a)
  mb = len(b)
  if ma == mb :
    if sum(a) < sum(b):
      return 1
    else:
      return 0

  i = 1
  while ma > i and mb > i:
    if a[i] > b[i]:
      return 0
    elif a[i] < b[i]:
      return 1
    i += 1

  return 0

if sum(a) + sum(b) <= k:
  print(n+m)
  exit()
x = -1
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]:
    if x == -1:
      x = calc(a[ni:] ,b[mi:])
    if x == 0:
      ans += b[mi]
      mi += 1
    elif x == 1:
      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:
m,n,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
len_a = len(a)
len_b = len(b)
i_a = 0
i_b = 0
sum_time = []
sum_n = 0

while sum_n <= k:
    if len_a <= i_a and len_b <= i_b:
        break
    elif len_a <= i_a:
        sum_time.append(b[i_b])
        sum_n += b[i_b]
        i_b += 1
    elif len_b <= i_b:
        sum_time.append(a[i_a])
        sum_n += a[i_a]
        i_a += 1
    elif a[i_a] <= b[i_b]:
        sum_time.append(a[i_a])
        sum_n += a[i_a]
        i_a += 1
    else:
        sum_time.append(b[i_b])
        sum_n += b[i_b]
        i_b += 1

if sum(sum_time) > k:
    sum_time.pop()

print(len(sum_time))

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

ans = 0


def dfs(x, y, read, z):
    while True:
        if len(x) == 0 and len(y) == 0:
            return read
        elif z <= 0:
            return read
        elif len(x) == 0:
            time = y.popleft()
        elif len(y) == 0:
            time = x.popleft()
        elif x[0] < y[0]:
            time = x.popleft()
        elif x[0] > y[0]:
            time = y.popleft()
        elif x[0] == y[0]:
            if dfs(deque(list(x.copy())[1:]), y.copy(), read, z - x[0]) > dfs(x.copy(), deque(list(y.copy())[1:]), read, z - y[0]):
                time = x.popleft()
            else:
                time = y.popleft()

        if z - time >= 0:
            z -= time
            read += 1
        else:
            return read


ans = dfs(a, b, 0, k)
print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.append(100000000000)
b.append(100000000000)
i, j, ans = 0, 0, 0
while k > 0:
    if i == n and j == m: break
    if a[i] < b[j]:
        k -= a[i]
        i += 1
    else:
        k -= b[j]
        j += 1
    if k >= 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

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

a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]

b.append(k)
cnt = 0
for i in range(n-1):
    a[i+1] += a[i]

for j in range(m):
    b[j+1] += b[j]

# print(a, b)
ans = 0
for i in range(n):
    nokori = k-a[i]
    r, l = 0, m
    if nokori < 0:
        break
    if b[0] > nokori:
        ans = max(i+1, ans)
        continue

    while(l-r > 1):
        if b[(r+l)//2] <= nokori:
            r = (r+l)//2
        else:
            l = (r+l)//2
        # print(l, r)
    ans = max(i+l+1, ans)
    # print(i, r, l, nokori)
print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = [int(_) for _ in input().split()]
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]

print(n, m, k)
print(a, b)

maxrecord = 0

for i in range(1, n + 1):
    left = k - sum(a[:i])
    if left < 0:
        counter = i - 1
        if maxrecord < counter:
            maxrecord = counter
        break
    counter = i

    for j in range(1, m + 1):
        if left - sum(b[:j]) < 0:
            if maxrecord < counter:
                maxrecord = counter
            break
        counter += 1

print(counter)

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:
    sum1 = 0
    sum2 = 0
    i1=0
    i2=0
    while i1<len(a) and sum1<k:
        sum1+=a[i1]
        i1+=1
    while i2<len(b) and sum2<k:
        sum2+=b[i2]
        i2+=1
    if i1>i2:
        ans+=i1
        a=a[i1:]
        k-=sum1
    else:
        ans+=i2
        b=b[i2:]
        k-=sum2
    if k<0:
        ans-=1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)

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
yomu = 0

def ruiseki(list):
    cnt = 0
    for i in list:
        cnt += i
    return cnt

while True:
    if atop >= n and btop >= m:
        break
    if a[atop] < b[btop]:
        yomu = a[atop]
        atop += 1
    elif a[atop] > b[btop]:
        yomu = b[btop]
        btop += 1
    else:
        if ruiseki(a[atop:n]) <= ruiseki(b[btop:m]):
            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()))

# まずaを全部読む
# 全部読めたならbも読む
# 最後の本を捨てて、それがなければどこまでいけるかを試す

ans = 0
cost = 0
b_i = 0
if not (a[0] >= k and b[0] >= k):
  while 1:
    if ans >= n:
      if ans-n>=m:
        break
      _next = b[n-ans]
      b_i += 1
    else:
      _next = a[ans]
    if (cost + _next) <= k:
      ans += 1
      cost += _next
    else:
      b_i -= 1
      break

  max_ans = ans
  if b_i == 0 or b_i == -1:
    for i in range(ans-1,-1,-1): # 2から
      ans -= 1
      cost -= a[i]
      while cost < k and b_i < m:
        ans += 1
        cost += b[b_i]
        b_i += 1
      max_ans = max(max_ans, ans)
  else:
    for i in range(n-1,-1,-1):
      ans -= 1
      cost -= a[i]
      while cost < k and b_i < m:
        ans += 1
        cost += b[b_i]
        b_i += 1
      max_ans = max(max_ans, ans)

  if a[0] <= k:
    print(max_ans)
  else:
    ans = 0
    cost = 0
    _next = 0
    while 1:
      if ans >= m:
        break
      _next = b[ans]
      if cost + _next > k:
        break
      cost += _next
      ans += 1
    print(ans)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
from sys import stdin
An, Bn, t = [int(x) for x in stdin.readline().rstrip().split()]

A = [int(x) for x in stdin.readline().rstrip().split()]
B = [int(x) for x in stdin.readline().rstrip().split()]

idxA = idxB = cnt = 0

for i in range(An + Bn):
	if t < 0 : break

	if An > idxA :
		t -= A[idxA]
		if t < 0 : break
		cnt += 1
		idxA += 1

	if Bn > idxB :
		t -= B[idxB]
		if t < 0 : break
		cnt += 1
		idxB += 1

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()))
o = n + m
if sum(a+b) <= k:
    print(n+m)
    exit()
a_l = int(len(a))
b_l = int(len(b))
if a_l < b_l:
    c = b_l - a_l
    a = a + [10 ** 10 for i in range(c)]
elif b_l < a_l:
    c = a_l - b_l
    b = b + [10 ** 10 for i in range(c)]
t = 0
#print(a,b)
for i in range(o):
    #print(a)
    if a[0] < b[0]:
        t += a[0]
        a = a[1:]
    else:
        t += b[0]
        b = b[1:]
    #print(a[0],b[0])
    #print(t)
    if t > k:
        print(i)
        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()))
num=min(N,M)
time=0
ans=0
while len(A)!=0 and len(B)!=0 :
  if time>K:
    print(ans-1)
    exit()
  elif time<=K:
    time+=min(A[0],B[0])
    ans+=1
    if A[0]<B[0]:
      del A[0]
    else:
      del B[0]
if len(A)==0:
  while len(B)!=0:
    if time>K:
      print(ans-1)
      exit()
    elif time<=K:
      time+=B[0]
      ans+=1
      del B[0]
if len(B)==0:
  while len(A)!=0:
    if time>K:
      print(ans-1)
      exit()
    else:
      time+=A[0]
      ans+=1
      del A[0]
if time>K:
  print(ans-1)
else:
  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()))
ct=0
ans=0
if sum(a)+sum(b)<k:
    ans=m+k
else:
    while 1:        
        if a[0]<b[0]:
            if ct+a[0]>k:
                break
            ct+=a[0]
            a.pop(0)
            a.append(999999999)
        elif a[0]>b[0]:
            if ct+b[0]>k:
                break
            ct+=b[0]
            b.pop(0)
            b.append(9999999999)
        else:
            if ct+b[0]>k:
                break
            ct+=a[0]
            if sum(a)>sum(b):
                a.pop(0)
                a.append(9999999999)
            else:
                b.pop(0)
                b.append(9999999999)
        ans+=1
print(ans)

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

if sum(A) + sum(B) < K:
    print(N + M)
    exit()

ans = 0

while K > 0:
    if len(A) != 0:
        if len(B) == 0 or A[0] <= B[0]:
            if A[0] > K:    # 所要時間を超えてしまう
                break
            # print(A[0], K-A[0])
            K -= A.popleft()
            ans += 1
            continue
    if len(B) != 0:
        if len(A) == 0 or A[0] >= B[0]:
            if B[0] > K:    # 所要時間を超えてしまう
                break
            # print(B[0], K-B[0])
            K -= B.popleft()
            ans += 1
            continue

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque


def main():
    N, M, K = map(int, input().split())
    n_list = list(map(int, input().split()))
    m_list = list(map(int, input().split()))
    n_idx = 0
    m_idx = 0
    num_books = 0
    while (n_idx <= len(n_list) - 1) or (m_idx <= len(m_list) - 1):
        if (n_idx <= len(n_list) - 1) and (m_idx <= len(m_list) - 1):
            if n_list[n_idx] < m_list[m_idx]:
                tmp_time = n_list[n_idx]
                if K - tmp_time >= 0:
                    num_books += 1
                    n_idx += 1
                    K -= tmp_time
                else:
                    break
            else:
                tmp_time = m_list[m_idx]
                if K - tmp_time >= 0:
                    num_books += 1
                    m_idx += 1
                    K -= tmp_time
                else:
                    break

        elif n_idx <= len(n_list) - 1:
            tmp_time = n_list[n_idx]
            if K - tmp_time >= 0:
                num_books += 1
                n_idx += 1
                K -= tmp_time
            else:
                break

        else:
            tmp_time = m_list[m_idx]
            if K - tmp_time >= 0:
                num_books += 1
                m_idx += 1
                K -= tmp_time
            else:
                break

    print(num_books)

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

a.sort()
b.sort()
s,c = 0,0
if a[0] < k or b[0] < k:
    for i in range(m+n):
        if s < k and i < len(a) and s+a[i]<k:
            s += a[i]
            c += 1
        if s<k and i < len(b) and s+b[i] < k:
            s += b[i]
            c += 1

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()))
a.append(10**9+1)
b.append(10**9+1)
cnt = 0
cnt2 = 0
mo = 0
for i in range(n+m+1):
  if a[cnt] >= b[cnt2]:
    mo += b[cnt2]
    if mo > k:
      print(cnt+cnt2)
      exit(0)
    cnt2+=1
  else:
    mo += a[cnt]
    if mo > k:
      print(cnt+cnt2)
      exit(0)
    cnt += 1
print(cnt+cnt2)

Submission status: Wrong Answer

Solution code:
N, M, KK = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
k = []


max = N + M
  #print(max)
summ = 0

for i in range(max):

  if len(a) > 0 and len(b) > 0:
    #print(a[0], b[0])
    if a[0] < b[0]:
      k.append(a[0])
      a.pop(0)
    else:
      k.append(b[0])
      b.pop(0)
    
    if KK >= sum(k) :
      summ += 1
    else:
      break
      
  elif len(a) > 0 and len(b) == 0:
    k.append(a[0])
    
    if KK >= sum(k) :
      summ += 1
      a.pop(0)
    else:
      break
  
  elif len(a) == 0 and len(b) > 0:
    k.append(b[0])
    
    if KK >= sum(k) :
      summ += 1
      b.pop(0)
    else:
      break
    
  else:
    break
    
  #print(a)
  #print(b)
  #print(KK)
print(summ)

Submission status: Wrong Answer

Solution code:
def main():
    n, m, k = map(int, input().split())
    alis = list(map(int, input().split()))
    blis = list(map(int, input().split()))
    adic = {}
    bdic = {}
    for i in range(len(alis)):
        adic[i+1] = alis[i]
    for i in range(len(blis)):
        bdic[i+1] = blis[i]

    time = 0
    ans = 0
    a = 1
    b = 1
    while time <= k:
        #print(alis, blis, len(alis), k, time)
        if a > len(adic) and b > len(bdic):
            break
        elif a > len(adic) and bdic[b] <= k - time:
            time += bdic[b]
            b += 1
            ans += 1
        elif b > len(bdic) and adic[a] <= k - time:
            time += adic[a]
            a += 1
            ans += 1
        elif a > len(adic) and bdic[b] > k - time:
            break
        elif b > len(bdic) and adic[a] > k - time:
            break
        
        else:
            #print(alis, blis)
            if adic[a] <= bdic[b] and time + adic[a] <= k:
                #print(time, alis[0], blis[0])
                time += adic[a]
                a += 1
                ans += 1
            elif adic[a] > bdic[b] and time + bdic[b] <= k:
                #print(time)
                time += bdic[b]
                b += 1
                ans += 1
            else:
                break


    print(ans)

    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
times_a = list(map(int, input().split()))
times_b = list(map(int, input().split()))
read_time = 0
count = 0
while read_time <= K:
    if len(times_a) != 0 and len(times_b) != 0:
        if times_a[0] <= times_b[0] and (read_time + times_a[0]) <= K:
            read_time += times_a[0]
            times_a.pop(0)
            count += 1
        else:
            if (read_time + times_b[0]) <= K:
                read_time += times_b[0]
                times_b.pop(0)
                count += 1
            else:
                break
    elif len(times_a) == 0 and len(times_b) != 0 and (read_time + times_b[0]) <= K:
        #bから
        read_time += times_b[0]
        times_b.pop(0)
        count += 1
    elif len(times_b) == 0 and len(times_a) != 0 and (read_time + times_a[0]) <= K:
        # aから
        read_time += times_a[0]
        times_a.pop(0)
        count += 1
    else:
        break
print(count)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
input = sys.stdin.readline

if __name__ == '__main__':
  n,m,k=map(int,input().strip("\n").split())
  A=list(map(int,input().strip("\n").split()))
  B=list(map(int,input().strip("\n").split()))
#  A.append(10**9+1)
#  B.append(10**9+1)

  def dfs(a,b,k,s):
    if k<0:
      return s-1
    if k==0:
      return s
    if a==n-1:
      if k-A[a]>=0:
        ansA=s+1
      else:
        ansA=s
    elif a<n:
      ansA=dfs(a+1,b,k-A[a],s+1)
    else:
      ansA=s

    if b==m-1:
      if k-B[b]>=0:
        ansB=s+1
      else:
        ansB=s
    elif b<m:
      ansB=dfs(a,b+1,k-B[b],s+1)
    else:
      ansB=s
    return max(ansA,ansB)

  ans=dfs(0,0,k,0)
  print(ans)