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())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

from itertools import accumulate
from bisect import bisect_right
aacc = list(accumulate(As))
bacc = list(accumulate(Bs))

# print(aacc)
ans = 0
for i in range(n):
    a = aacc[i]
    if k - a < 0:continue
    # print(a, k-a)
    n = bisect_right(bacc, k-a)
    # print("index a",i+1, "b",n)
    ans = max(i+1+n,ans)

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.insert(0, 0)
b.insert(0, 0)
maxNum = sum(a) + sum(b)
cnt = n+m
while maxNum > k:

    if cnt == 0:
        break
    

    if a[-1] > b[-1]:
        maxNum -= a[-1]
        a.pop(-1)

    elif a[-1] < b[-1]:
        maxNum -= b[-1]
        b.pop(-1)

    cnt -=1


print(cnt)

Submission status: Wrong Answer

Solution code:
import itertools
from bisect import bisect

N, M, K = [int(n) for n in input().split()]
A = [int(n) for n in input().split()]
B = [int(n) for n in input().split()]
C = []
while True:
    if len(A) !=0 and len(B)!=0:
        c = min(A[0], B[0])
        if c == A[0]:
            C.append(A.pop(0))
        else:
            C.append(B.pop(0))
    else:
        if len(A)==0:
            C+=B
            break
        else:
            C+=A
            break
print(bisect([x for x in itertools.accumulate(C)], K))

Submission status: Wrong Answer

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

ai = 0
bi = 0
 
aa = a[ai]
bb = b[bi]
 
while True:
    if aa == bb:
        if len(a) > ai + 1:
            if len(b) > bi + 1:
                if a[ai + 1] < b[bi + 1]:
                    time += aa
                    ai += 1
                    aa = a[ai]
                else:
                    time += bb
                    bi += 1
                    bb = b[bi]
            else:
                time += aa
                ai += 1
                aa = a[ai]
        else:
            time += bb
            bi += 1
            if len(b) > bi:
                bb = b[bi]
            else:
                bb = 10000000000
    
    elif aa < bb:
        time += aa
        ai += 1
        if len(a) > ai:
            aa = a[ai]
        else:
            aa = 10000000000
    else:
        time += bb
        bi += 1
        if len(b) > bi:
            bb = b[bi]
        else:
            bb = 10000000000
    
    if time <= k:
        res += 1
    else:
        break
print(res)

Submission status: Wrong Answer

Solution code:
A=[]
B=[]
books = 0
time = 0
n, m, k = map(int,input().split())
i = n-1
j = m - 1
A = list(map(int,input().strip().split()))[:n] 
B = list(map(int,input().strip().split()))[:m] 
while not(time > k) :
    if ((i> -1 and j> -1 and A[i]<B[j]) or (i>-1 and not(j>-1))):
        time = time+A[i]
        i=i-1
        books=books+1
    elif ((i> -1 and j> -1 and (not(A[i]<B[j]))) or (j>-1 and not(i>-1))):
        time = time+B[j]
        j=j-1
        books=books+1
print(books)

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

Aflg=0
Bflg=0
jikan=0
count=0


while True:
    print(Aflg,Bflg,jikan,count)
    if jikan>K:
        break
    else:
        if A[Aflg] <= B[Bflg]:
            jikan+=A[Aflg]
            Aflg+=1
            if Aflg>=N:
                Aflg=N
        else:
            jikan+=B[Bflg]
            Bflg+=1
            if Bflg>=N:
                Bflg=N
        count+=1

print(count-1)

Submission status: Wrong Answer

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

if(sum(As) + sum(Bs) <= K):
    print(N + M)
    exit()


Asruisekiwa = []
Bsruisekiwa = []

Asruisekiwa.append(As[0])
Bsruisekiwa.append(Bs[0])

for i, j in enumerate(As[1:]):
    Asruisekiwa.append(Asruisekiwa[-1]+j)

for i, j in enumerate(Bs[1:]):
    Bsruisekiwa.append(Bsruisekiwa[-1] + j)

#print(Asruisekiwa)
#print(Bsruisekiwa)

ans = 0
Bsruisekiwa.append

for index, i in enumerate(Asruisekiwa):

    if(i > K):
        break

    tmp = i
    maxcheck = K - i


    hoge = bisect.bisect_left(Bsruisekiwa, maxcheck) + 1

    ans = max(ans, index + hoge)

#        print(ans, tmp, hoge, maxcheck)

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

from itertools import accumulate
aa=list(accumulate(a))
bb=list(accumulate(b))

from bisect import bisect_left,bisect

kmax=0
for i in range(n):
    if k<aa[i]:
        break
    kk=k-aa[i]
#    k2=min(bisect(bb,kk),m-1)
    k2=bisect(bb,kk)
    if k2<m-1 and bb[k2+1]==kk:
        k2+=1
#    print(i,k2)
    kmax=max(kmax,k2+i+1)

print(kmax)

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


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 += a[0]
      a.pop(0)
    else:
      k += b[0]
      b.pop(0)
    
    if KK >= k :
      summ += 1
    else:
      break
      
  elif len(a) > 0 and len(b) == 0:
    k += a[0]
    
    if KK >= k :
      summ += 1
      a.pop(0)
    else:
      break
  
  elif len(a) == 0 and len(b) > 0:
    k += b[0]
    
    if KK >= 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())
    from collections import deque
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    ad = deque(a)
    bd = deque(b)
    cnt = 0
    inf = 10**18
    for i in range(m+n):
        if n > 0:
            p = ad.popleft()
        if m > 0:
            q = bd.popleft()
        if p == q:
            for j in range(min(n-1,m-1)):
                if ad[j] > bd[j]:
                    p += 1
                    break
                elif ad[j] < bd[j]:
                    q += 1
                    break
        if p == q:
            if n > m:
                q += 1
        if p < q:
            n -= 1
            bd.appendleft(q)
            k -= p
        else:
            ad.appendleft(p)
            m -= 1
            k -= q
        if k >= 0:
            cnt += 1
        if k <= 0:
            break
        p = inf
        q = inf
    print(cnt)              


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

da = []
da.append([a[0], 1])
now = 0
for i in range(1,N):
    if a[i] == a[i-1]:
        da[now][1] += 1
    else:
        da.append([a[i], 1])
        now += 1
db = []
db.append([b[0], 1])
now = 0
for i in range(1,M):
    if b[i] == b[i-1]:
        db[now][1] += 1
    else:
        db.append([b[i], 1])
        now += 1

Na = len(da); Mb = len(db)
ai = 0; bi = 0

dp = 0

for i in range(N+M):
    if dp > K:
        break
    if ai == Na:
        res = db[bi][0]
        db[bi][1] -= 1
        if db[bi][1] == 0:
            bi += 1
    elif bi == Mb:
        res = da[ai][0]
        da[ai][1] -= 1
        if da[ai][1] == 0:
            ai += 1

    elif da[ai][0] == db[bi][0]:
        ra = ai; rb = bi
        while da[ra][0] == da[rb][0]:
            ra += 1; rb += 1
            if ra == Na or rb == Mb:
                res = da[ai][0]
                da[ai][1] -= 1
                if da[ai][1] == 0:
                    ai += 1
                break
            if da[ra][0] < da[rb][0]:
                res = da[ai][0]
                da[ai][1] -= 1
                if da[ai][1] == 0:
                    ai += 1
                break
            elif da[ra][0] < da[rb][0]:
                res = db[bi][0]
                db[bi][1] -= 1
                if db[bi][1] == 0:
                    bi += 1
                break

    elif da[ai][0] < db[bi][0]:
        res = da[ai][0]
        da[ai][1] -= 1
        if da[ai][1] == 0:
            ai += 1
    else:
        res = db[bi][0]
        db[bi][1] -= 1
        if db[bi][1] == 0:
            bi += 1

    #dp[i] = dp[i-1] + res
    dp += res
    #print(dp)
#import bisect
#print(bisect.bisect_right(dp, K)-1)

if dp > K:
    print(i-1)
else:
    print(i+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()))

AL = []
BL = []
a = 0
for i in A:
    a += i
    AL.append(a)
a = 0
for i in B:
    a += i
    BL.append(a)

#print(AL)
#print(BL)

a = 0
for i in range(len(AL)):
    if AL[i] > k:
        a = i
        break
else:
    a = len(AL)

b = 0
for i in range(len(BL)):
    if BL[i] > k:
        b = i
        break
else:
    b = len(BL)

#print(a,b)

m = a
u = 0
for j in reversed(range(a)):
#    print(j,u)
    t = k-AL[j]
    for i in range(u,b):
#        print(i)
        if t-BL[i]>=0:
            if m < j+1 + i +1:
                m = j+1 + i +1
#                print(m)
        else:
            if i >0:
                u = i-1
            break
        
    if j+1+b<m:
        break
if a == 0 and b > 0:
    m = b
print(m)

Submission status: Wrong Answer

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

minute = 0
i = 0
j = 0

while i < n and j < m:
  if alist[i] < blist[j]:
    minute += alist[i]
    if minute > k:
      break
    i += 1
  else:
    minute += blist[j]
    if minute > k:
      break
    j += 1

if minute > k:
  print(i+j)
elif i < n:
  while i < n:
    minute += alist[i]
    if minute > k:
      break
    i += 1
  print(i+j)
else:
  while j < m:
    minute += blist[j]
    if minute > k:
      break
    j += 1  
  print(i+j)

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

time = 0
ai = 0
bj = 0
am = 0
bm = 0

while time <= K:
  if ai < len(A):
    am = A[ai]
  else:
    am = K
  if bj < len(B):
    bm = B[bj]
  else:
    bm = K

  if am < bm:
    if (time + am) > K:
      break
    else:
      time += am
      ai += 1
  else:
    if (time + bm) > K:
      break
    else:
      time += bm
      bj += 1

print(ai + bj)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M, K = map(int, input().split())
A = input().split()
B = input().split()
for i in range(len(A)):
  A[i] = int(A[i])
for i in range(len(B)):
  B[i] = int(B[i])
A_cumsum = np.array(A).cumsum()
B_cumsum = np.array(B).cumsum()
max_count = 0
for i in range(M):
  if B_cumsum[i] <= K and max_count <= B_cumsum[i]:
    max_count = i + 1
  else:
    M = i
    break
for i in range(N):
  if A_cumsum[i] <= K and max_count <= A_cumsum[i]:
    max_count = i + 1
  else:
    N = i 
    break
for i in range(N):
  for j in range(M):
    if A_cumsum[i] + B_cumsum[j] <= K and max_count <= A_cumsum[i] + B_cumsum[j]:
      max_count = i + j + 2
    else:
      break
print(max_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()))

ai=0
bi=0
time=0

while ai < n and bi < m:
  if a[ai]<b[bi]:time+=a[ai];ai+=1
  else:time+=b[bi];bi+=1
    
  if time >= k:break
    
if n > m:
  while ai < n:
    time+=a[ai];ai+=1
    if time >= k:break

if n < m:
  while bi < m:
    time+=b[bi];bi+=1
    if time >= k:break
      
print(ai+bi)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
import bisect

N, M, K = map(int, input().split())
A = list(map(int, sys.stdin.readline().rsplit()))
B = list(map(int, sys.stdin.readline().rsplit()))

sA = [0] + list(itertools.accumulate(A))
sB = [0] + list(itertools.accumulate(B))

res = 0
for i, a in enumerate(sA):
    if K < a:
        break
    j = bisect.bisect_left(sB, K - a)
    if j < M and sB[j] > K - a:
        j = j - 1
    res = max(res, i + j)

print(res)

Submission status: Wrong Answer

Solution code:
N,M,K=list(map(int,input().split()))
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
totalbook = 0
totaltime = 0
for a in a_list:
  if totaltime+a <= K:
    totaltime+=a
    totalbook+=1
  else:
    break
ans = totalbook
nowaind = totalbook-1 if totalbook > 0 else 0
nowbind = 0
for b in b_list:
  if totaltime+b<=K:
    totaltime+=b
    totalbook+=1
    nowbind+=1
  else:
    break
ans = max(ans,totalbook)
while nowaind >= 0:
  totalbook-=1
  totaltime-=a_list[nowaind]
  nowaind-=1

  for b in range(nowbind,len(b_list)):
    while nowaind >= 0 and totaltime+b_list[b]>K:
      totalbook-=1
      totaltime-=a_list[nowaind]
      nowaind-=1
    
    if totaltime+b_list[b]<=K:
      totaltime+=b_list[b]
      totalbook+=1
      nowbind+=1
    else:
      break
  ans = max(ans,totalbook)
print(ans)

Submission status: Wrong Answer

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

from collections import deque

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

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

an = an
bn = bn

vMax = 10**9+10

import itertools

accum_a = [0]
accum_b = [0]



candidate = []

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


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

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


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

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

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

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


print(Find(accum_a, accum_b))

Submission status: Wrong Answer

Solution code:
from bisect import bisect

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
R_B = [0]*(M+1)
i = 0
while i < M:
  R_B[i+1] = R_B[i]+B[i]
  i += 1 
ans = 0
i = 0
while i < N and K >= A[i]:
  K -= A[i]
  idx = bisect(R_B, K)
  ans = max(ans, i+idx)
  R_B = R_B[:idx+1]
  i += 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(" ")))
for i in range(len(b)):
  a.append(b[i])
a.sort()
j=0
d=0
c=0
while(d<=k and j<len(a)):
  d=d+a[j]
  j=j+1
  c=c+1
if(d>k):
  print(c-1)
else:
  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()))

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

if sum(a) + sum(b) <= k:
  print(n+m)
  exit()
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
  elif a[ni] > b[mi]:
    ans += b[mi]
    mi += 1
  elif a[ni] == b[mi]:
    if sum(a[ni:]) > sum(b[mi:]):
      ans += b[mi]
      mi += 1
    else:
      ans += a[ni]
      ni += 1

  if ans <= k:
    cnt += 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()) ) 
C = []
while sum(C) <= K:
    try:
        if A[0] < B[0]:
            C.append(A[0])
            del A[0]
        else:
            C.append(B[0])
            del B[0]
    except IndexError:
        if len(A) != 0:
            C.append(A[0])
            del A[0]
        elif len(B) != 0:
            C.append(B[0])
            del B[0]
        else:
            break
print(sum(C))
if sum(C) > K:
    print(len(C)-1)
else:
    print(len(C))

Submission status: Wrong Answer

Solution code:
a = input().split(" ")
N = int(a[0])
M = int(a[1])
K = int(a[2])
Ai = input().split(" ")
Bi = input().split(" ")
Ai = [int(s) for s in Ai]
Bi = [int(s) for s in Bi]
time_ = int(K)
time0 = 0
acount = 0
bcount = 0

for i in range(10000000000000000):
    try:
        time0 += Ai[i]
        if time0 > time_:
            time0 -= Ai[i]
            break
        acount += 1
    except IndexError:
        break
atime = time0
time0 = 0
for i in range(10000000000000000):
    try:
        time0 += Bi[i]
        if time0 > time_:
            time0 -= Bi[i]
            break
        bcount += 1
    except IndexError:
        break
btime = time0
allc = bcount
if bcount > acount:
    hic = bcount
else:
    hic = acount
# AiからBiに移す
cip = 0
for i in range(acount):
    ci = i + cip
    try:
        while time0 + Ai[ci] <= time_:
            time0 += Ai[ci]
            print(time0)
            allc += 1
            ci += 1
            cip += 1
            if hic < allc:
                hic = allc
    except IndexError:
        pass
    try:
        time0 -= Bi[bcount - 1]
        bcount -= 1
        allc -= 1
    except IndexError:
        pass
    try:
        while time0 + Ai[ci] <= time_:
            time0 += Ai[ci]
            allc += 1
            ci += 1
            cip += 1
            if hic < allc:
                hic = allc
    except IndexError:
        break

print(hic)

Submission status: Wrong Answer

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

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


ans = 0
temp = 0
for i in range(len(a)):
    if temp+a[i] <= k:
        temp+=a[i]
        ans += 1

    else:
        break

for i in range(len(b)):
    if temp+b[i] <= k:
        temp+=b[i]
        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()))

i=0
sum=0
y=0
l1=(len(A)-1)
l2=(len(B)-1)
if A[0]>=K:
    print(int(0))
else:
    while (True):
        if i<=l1 or i<=l2:
            if i<=l1:
                sum+=A[i]
                if sum>K:

                    break
                else:
                    y+=1

            if i<=l2:
                sum+=B[i]
                if sum>K:
                    break
                else:
                    y+=1

            i+=1
        else:
            break
    print(int(y))

Submission status: Wrong Answer

Solution code:
import sys
 
n, m, k = map(int, sys.stdin.readline().split())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))

time = 0
left_outer = 0
right_outer = 0
cnt_list = []
for a_i in a:
    time_tmp = time + a_i
    if time_tmp <= k:
        time = time_tmp
        left_outer += 1
    else:
        break
for b_i in b:
    time_tmp = time + b_i
    if time_tmp <= k:
        time = time_tmp
        right_outer += 1
    else:
        break
cnt_list.append(left_outer+right_outer)

for _ in range(left_outer+1):
    time -= a[left_outer-1]
    while True:
        if right_outer == len(b):
            break
        time_tmp = time + b[right_outer]
        if time_tmp <= k:
            time = time_tmp
            right_outer += 1
        else:
            break
    left_outer -= 1
    cnt_list.append(left_outer + right_outer)

print(max(cnt_list))

Submission status: Wrong Answer

Solution code:
data = [int(k) for k in input().split()]

A = data[0]
B = data[1]
K = data[2]

Abooks = [int(k) for k in input().split()]
Bbooks = [int(k) for k in input().split()]


time = 0
nbOfBooks = 0

while ((time + Bbooks[0]) <= K or (time + Abooks[0]) ) <= K:
	
		
	if Abooks[0] >= Bbooks[0]:
		
		time += Bbooks[0]
		
		if len(Bbooks) == 1:
			Bbooks[0] = 10**9+1
		else:

			Bbooks.pop()
		
		nbOfBooks += 1

	else:
		
		time += Abooks[0]
		
		if len(Abooks) == 1:
			Abooks[0] = 10**9+1
		
		else:

			Abooks.pop()
		nbOfBooks += 1 


print(nbOfBooks)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
pa = abs(N-M) + 1
A = list(map(int, input().split()))+ [1000000010]
B = list(map(int, input().split()))+ [1000000010]
c = 0
while K >= A[0] or K >= B[0]:
    if A[0] < B[0]:
        K -= A.pop(0)
        c += 1
    elif A[0] > B[0]:
        K -= B.pop(0)
        c += 1
    if A[0] + B[0] == 1000000010*2:
        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(' ')))


lim = n+m
i = 0
cnt_a = 0
loop = len(a)
while k > 0 and i < loop:
    if k - a[i] >= 0:
        k -= a[i]
        i += 1
        cnt_a += 1
    else:
        break

i = 0
cnt_b = 0
loop = len(b)
while k > 0 and i < loop:
    if k - b[i] >= 0:
        k -= b[i]
        i += 1
        cnt_b += 1
    else:
        break

cnt = cnt_a + cnt_b
max_cnt = cnt
kk = k

for j in range(cnt_a-1,-1,-1):
    if max_cnt == lim:
        break
    cnt -= 1
    kk += a[j]
    while kk > 0 and i < loop:
        if k - b[i] >= 0:
            k -= b[i]
            i += 1
            cnt += 1
        else:
            break
    if max_cnt < cnt:
        max_cnt = cnt

print(max_cnt)

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

ans = 0
now = 0

a = [now]
b = [now]

for i in range(N):
    now += A[i]
    a.append(now)
now = 0
for i in range(M):
    now += B[i]
    b.append(now)


for i in range(N+1):
    now = a[i]
    ans2 = i
    for j in range(M+1):
        if now + b[j] > K:
            break
        now += b[j]
        ans2 += j
        if ans2 > ans:
            ans = ans2

print(ans)

Submission status: Wrong Answer

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

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

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

    if (ind_B >= M and ind_A < N): # Bを読み終わったからAの本を読む
        time += A[ind_A]
        ind_A += 1
        ans += 1
    elif (ind_A >= N and ind_B < M) : # Aを読み割ったからBの本を読む
        time += B[ind_B]
        ind_B += 1
        ans += 1
    elif  A[ind_A] <= B[ind_B]: #Aの方が先に読み終わるからAの本を読む
        time += A[ind_A]
        ind_A += 1
        ans += 1
    elif A[ind_A] > B[ind_B]: #Bの方が先に読み終わるからBの本を読む
        time += B[ind_B]
        ind_B += 1
        ans += 1
    
    if time > K:
        break
    
print(ans - 1)

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

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_count = 0
time_count = 0
a_num = 0
b_num = 0

for i in range(4000000):
  if len(A) == 0 and len(B) == 0:
    break
  elif len(A) == 0:
    time_count = time_count + B[0]
    if time_count > K:
      break
    else:
      book_count = book_count + 1
      B.pop(0)
  elif len(B) != 0 and A[0] > B[0]:
    time_count = time_count + B[0]
    if time_count > K:
      break
    else:
      book_count = book_count + 1
      B.pop(0)
  elif len(B) == 0:
    time_count = time_count + A[0]
    if time_count > K:
      break
    else:
      book_count = book_count + 1
      A.pop(0)
  elif len(A) != 0 and A[0] < B[0]:
    time_count = time_count + A[0]
    if time_count > K:
      break
    else:
      book_count = book_count + 1
      A.pop(0)
      
print(book_count)

Submission status: Wrong Answer

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

num = 0

for i in range(n + m):
    if len(a_list) != 0:
        x = a_list[0]
    else:
        x = 1000000000000
    if len(b_list) != 0:
        y = b_list[0]
    else:
        y = 1000000000000

    print(x, y)
    if x < y:
        k -= x
        a_list.pop(0)
        num += 1
    else:
        k -= y
        b_list.pop(0)
        num += 1
    if k < 0:
        break

if len(a_list) == 0 and len(b_list) == 0:
    print(num)
else:
    print(num - 1)

Submission status: Wrong Answer

Solution code:
import sys
N, M, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))

A_cn = 0
B_cn = 0
time = 0

for _ in range(len(A_list)+len(B_list)):
    if A_cn < len(A_list):
        a = A_list[A_cn]
    else:
        a = 10**10
    if B_cn < len(B_list):
        b = B_list[B_cn]
    else:
        b = 10**10

    if (K-time) < min(a,b):
        print(A_cn+B_cn)
        sys.exit()
    else:
        if a <= b:
            time += a
            A_cn += 1
        else:
            time += b
            A_cn += 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()))
temp=0
an,bn=0,0
ans=0
while temp<=k:
    if an>=n and bn>=m: break
    if an>=n:
        temp+=b[bn]
        if temp>k: break
        bn+=1
    elif bn>=m:
        temp+=a[an]
        if temp>k: break
        an+=1
    else:
        if a[an]<b[bn]:
            temp+=a[an]
            if temp>k: break
            an+=1
        elif a[an]>b[bn]:
            temp+=b[bn]
            if temp>k: break
            bn+=1
        else: #同じとき
            cnt=0
            while True:
                if an==n:
                    bn-=cnt
                    break
                if bn==m:
                    an-=cnt
                    break
                if a[an]<b[bn]:
                    temp+=a[an]
                    an+=1
                    bn-=cnt
                    break
                if a[an]>b[bn]:
                    temp+=b[bn]
                    bn+=1
                    an-=cnt
                    break
                temp+=a[an]
                if temp>k:
                    break
                an+=1
                bn+=1
                ans+=1
                cnt+=1
            if temp>k:
                break
    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()))

ans = 0
dp = [[-1 for _1 in range(N+1)] for _2 in range(M+1)]
dp[0][0] = 0
for i in range(N):
    dp[0][i+1] = dp[0][i] + A[i]
for j in range(M):
    dp[j+1][0] = dp[j][0] + B[j]

for m in range(1,M+1):
    if dp[m][0] > K:
        break
    for n in range(1,N+1):
        dp[m][n] = dp[m][0] + dp[0][n]
        if dp[m][n] > K:
            ans = max(ans,m+n-1)
            break
    else:
        ans = max(ans, m+N)
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()))
total = 0
ac = 0
bc = 0
count = 0
while True:
  if k < total:
    count -= 1
    break
  if bc < m:
    if ac < n and a[ac] < b[bc]:
      total += a[ac]
      ac += 1
      count += 1
      continue
    else:
      total += b[bc]
      bc += 1
      count += 1
      continue
  if ac < n:
    if bc < m and a[ac] > b[bc]:
      total += b[bc]
      bc += 1
      count += 1
      continue
    else:
      total += a[ac]
      ac += 1
      count += 1
      continue
  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()))
a = 0
b = 0
t_sum = 0
cnt = 0
flag = True

for _ in range(len(A)+len(B)+2):
  if A[a] <= B[b]:
    t_sum += A[a]
    cnt += 1
    a += 1
  else:
    t_sum += B[b]
    cnt += 1
    b += 1
  if t_sum > K:
    cnt -= 1
    break
  if a == len(A):
    for _ in range(len(B)+1):
      if b == len(B):
        flag = False
        break
      t_sum += B[b]
      cnt += 1
      b += 1
      if t_sum > K:
        cnt -= 1
        flag = False
        break
  if not flag:
    break
  if b == len(B):
    for _ in range(len(A)+1):
      if a == len(A):
        flag = False
        break
      t_sum += A[a]
      cnt += 1
      a += 1
      if t_sum > K:
        cnt -= 1
        flag = False
        break
  if not flag:
    break
print(cnt)

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()))
##print(A+B)
C = A+B
A = A
B = B
##print(C)
ans = 0
goukei = 0
if K >= sum(C):
    print(N+M)
else:
    while goukei <= K:
        if not A:
            goukei += B[0]
            B.pop(0)
            ans += 1
        elif not B:
            goukei += A[0]
            A.pop(0)
            ans += 1
        else:
            if A[0] <= B[0]:
                goukei += A[0]
                A.pop(0)
                ans += 1
            else:
                goukei += B[0]
                B.pop(0)
                ans += 1
    print(ans-1)

Submission status: Wrong Answer

Solution code:
N, M, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
a = [0]*N
b = [0]*M
a[0] = A[0]
b[0] = B[0]
ae = N-1
be = M-1
e = 0
for i in range(1, N):
    a[i] = a[i-1] + A[i]
    if(a[i] > K):
        ae = i-1
        break
for i in range(1, M):
    b[i] = b[i-1] + B[i]
    if(b[i] > K):
        be = i-1
        break
ans = 0
for i in range(ae, -1, -1):
    sum = a[i]
    for j in range(e, be+1):
        if a[i] + b[j] > K:
            e = max(j-1, 0)
            break
        ans = max(ans, i+j+2)
print(ans)