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 sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math
from collections import deque
import itertools
import heapq
#import bisect
from fractions import Fraction
import copy
from functools import lru_cache
from collections import defaultdict
import pprint

#oo=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
# ko=list("abcdefghijklmnopqrstuvwxyz")

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)

def soinsubunkai(n):
    a = []
    i = 1
    while i*i <= n:
        if n % i == 0 and i!=1:
            a.append(i)
            n=n//i

        if n% i !=0 or i==1:
            i += 1
    nokori=[n]
    return a + nokori


def main():
    n,m,k=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    maxcount=0
    totaltime=0
    maxa=0
    for i in range(n):
        if totaltime+a[i]<=k:
            totaltime+=a[i]
            maxcount+=1
        else:
            maxa=i-1
            break
    nowcount=maxcount
    for i in range(m):
        if totaltime+b[i]<=k:
            totaltime+=b[i]

            nowcount+=1
            maxcount=max(maxcount,nowcount)
        else:
            if maxa<0:
                break
            else:
                while maxa>=0:
                    if totaltime-a[maxa]+b[i]<=k:
                        totaltime=totaltime-a[maxa]+b[i]
                        maxa-=1
                    else:
                        if maxa>=1:
                            totaltime-=a[maxa]
                            maxa-=1
                            nowcount-=1

                        else:
                            break
    print(max(maxcount,nowcount))


if __name__ == "__main__":

    main()

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
A=[int(i) for i in input().split()]+[10**10]
B=[int(i) for i in input().split()]+[10**10]
a=b=ans=0
for _ in range(n+m+1):
    if A[a]<B[b]:
        k-=A[a]
        a+=1
    else:
        k-=B[b]
        b+=1
    if k<0:
        print(ans)
        exit()
    ans+=1

Submission status: Wrong Answer

Solution code:
def LI():return list(map(int,input().split()))
from collections import Counter, deque, defaultdict
INF=10**15
n,m,k=LI()
a=LI()
b=LI()
# if sum(a)+sum(b)<=k:
#     print(n+m)
#     exit()

a=a+[INF]
b=b+[INF]

i=0
j=0
while k>0:
    if a[i]<b[j]:
        if k-a[i]>=0:
            k-=a[i]
            a[i]=0
            i+=1
        else:
            break
        
    else:
        if k-b[j]>=0:
            k-=b[j]
            b[j]=0
            j+=1
        else:
            break
   
   
cnt=0     
for i in a+b:
    if i==0:
        cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

    ad = deque()
    ad.extend(A)
    bd = deque()
    bd.extend(B)

    ans = 0
    k = 0
    while True:
        if len(ad) == 0 and len(bd) == 0:
            break
        elif len(ad) == 0:
            x = bd.popleft()
        elif len(bd) == 0:
            x = ad.popleft()
        else:
            if ad[0] < bd[0]:
                x = ad.popleft()
            else:
                x = bd.popleft()
        if k + x <= K:
            k += x
            ans += 1
        else:
            break
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''

    N, M, K = [int(item) for item in input().split()]
    As = [int(item) for item in input().split()]
    Bs = [int(item) for item in input().split()]

    res = 0
    time = 0
    while time < K:
        if not As and not Bs:
            time = K + 1
        elif not As:
            time += Bs[0]
            del Bs[0]
            res +=1
        elif not Bs:
            time += As[0]
            del As[0]
            res += 1
        else:
            a = As[0]
            b = Bs[0]

            if a <= b and As:
                time += As[0]
                del As[0]
            elif Bs:
                time += b
                del Bs[0]
            res += 1  
            
    if time > K:
        print(res -1)
    else:
        print(res)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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

time = K
A_count = 0
B_count = 0
ans = 0

f_inf = float('inf')
A.append(f_inf)
B.append(f_inf)

for i in range(200001):
    if A_count >= N and B_count >= M:
        break
    if A[A_count] < B[B_count]:
        time -= A[A_count]
        if time < 0:
            break
        A_count += 1
        ans += 1
    elif A[A_count] >= B[B_count]:
        time -= B[B_count]
        if time < 0:
            break
        B_count += 1
        ans += 1

# if A_count >= N and B_count >= M:
# while time >= 0:
#     if A_count < N:
#         time -= A[A_count]
#         if time < 0:
#             break
#         ans += 1
#         A_count += 1
#     if B_count < M:
#         time -= B[B_count]
#         if time < 0:
#             break
#         ans += 1
#         B_count += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from sys import setrecursionlimit
import heapq

from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

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

nowa = 0
nowb = 0

li = []
total = 0

while total <= k:
    if nowa == n and nowb == m:
        break
    if nowa == n and nowb < m:
        total += b[nowb]
        li.append(b[nowb])
        nowb += 1
    elif nowa < n and nowb == m:
        total += a[nowa]
        li.append(a[nowa])
        nowa += 1  
    elif a[nowa] <= b[nowb]:
        total += a[nowa]
        li.append(a[nowa])
        nowa += 1
    elif a[nowa] > b[nowb]:
        total += b[nowb]
        li.append(b[nowb])
        nowb += 1

if sum(li) <= k:
    print(len(li))
else:
    print(len(li)-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() ) )

i = 0
j = 0
time = 0
read = 0

while i < n or j < m:
    if i == n:
        if time + b[ j ] > k:
            break
        else:
            time += b[ j ]
            read += 1
            j += 1
    elif j == m:
        if time + a[ i ] > k:
            break
        else:
            time += a[ i ]
            read += 1
            i += 1
    elif a[ i ] < b[ j ]:
        if time + a[ i ] > k:
            break
        else:
            time += a[ i ]
            read += 1
            i += 1
    elif a[ i ] >= b[ j ]:
        if time + b[ j ] > k:
            break
        else:
            time += b[ j ]
            read += 1
            j += 1
    
print( read )

Submission status: Wrong Answer

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, M, K = LI()
    A = collections.deque(LI())
    B = collections.deque(LI())

    ans = 0
    while K > 0:
        if A and not B or A and B and A[0] < B[0]:
            if K < A[0]:
                break
            K -= A[0]
            A.popleft()
            ans += 1
        elif B and not A or A and B and A[0] >= B[0]:
            if K < B[0]:
                break
            K -= B[0]
            B.popleft()
            ans += 1
        else:
            break

    print(ans)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,m,k=nm()
a=nl()
b=nl()

sm=0

ai=0
bi=0

cnt=0
for i in range(n+m):
  bk = 0
  if ai==n:
    bk = b[bi]
    bi+=1
  elif bi==m:
    bk = a[ai]
    ai+=1
  else:
    if a[ai] < b[bi]:
      bk = a[ai]
      ai+=1
    else:
      bk = b[bi]
      bi+=1

  if sm+bk > k:
    break
  sm+=bk
  cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
import itertools
import decimal
import math
from collections import Counter
import sys
input = sys.stdin.readline

N,M,K=map(int,input().split())
dp=[]*210000
ListA=list(map(int,input().split()))
ListB=list(map(int,input().split()))

total=0
Acnt=0
Bcnt=0
for i in range(N+M):
    if(Acnt>=N):
        total+=ListB[Bcnt]
        Bcnt+=1
    elif(Bcnt>=M):
        total+=ListA[Acnt]
        Acnt+=1
    else:
        if(ListA[Acnt]>ListB[Bcnt]):
            total+=ListB[Bcnt]
            Bcnt+=1
        else:
            total+=ListA[Acnt]
            Acnt+=1

    Cnt=Acnt+Bcnt
    if(total==K):
        break
    if(total>K):
        Cnt-=1
        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()))
ans = 0
i, j = 0, 0
while ans<K:
    if i<N:
        a = A[i]
    else:
        a = float('inf')
    if j<M:
        b = B[j]
    else:
        b = float('inf')
    if (a==float("inf") and b==float("inf")):
        break
    if a<=b:
        ans += a
        i += 1
    else:
        ans += b
        j += 1
print(i+j-1)

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

A.append(10000000000000)
B.append(10000000000000)

time = 0
a_num = 0
b_num = 0
flag = 0
for i in range(N+M):
    if A[a_num] <B[b_num]:
        time += A[a_num]
        a_num+=1
    else:
        time += B[b_num]
        b_num+=1
    if time > K:
        flag = 1
        break
if flag==0:
    print(a_num+b_num)
else:
    print(a_num+b_num-1)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

ans = 0
minutes = 0
while True:
    if len(a) == 0 and len(b) == 0:
        break
    elif len(a) > 0 and len(b) > 0:
        if a[0] >= b[0]:
            if ans + b[0] <= k:
                minutes += 1
                ans += b.popleft()
            else:
                break
        else:
            if ans + a[0] <= k:
                minutes += 1
                ans += a.popleft()
            else:
                break

    elif len(b) == 0 and (a[0] + ans) <= k:
        minutes += 1
        ans += a.popleft()
    elif len(a) == 0 and (b[0] + ans) <= k:
        minutes += 1
        ans += b.popleft()
    else:
        break

print(minutes)

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

time = 0
i = 0
j = 0
cnt = 0
a = A[i]
b = B[j]
while(time<K):
    if i >= N:
        a = 9999999999
    elif j >= M:
        b = 9999999999
    if a<b :
        time += a
        a = A[i]
        i += 1
    else :
        time += b
        b = B[j]
        j +=1
    cnt += 1
    if cnt >=(N+M):
        break
    if time > K:
        cnt -= 1
print(cnt)

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

# stopper
A.append(10**9 + 1)
B.append(10**9 + 1)

AA = []
BB = [] 

x = 0
for a in A:
    x += a
    AA.append(x)

x = 0
for b in B:
    x += b
    BB.append(x)

ai = 0
bi = 0
total = 0

while total <= K:
    if AA[ai] < BB[bi]:
        total += A[ai]        
        ai += 1
    else:
        total += B[bi]
        bi += 1

print(ai + bi-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()]
r=0
c=0
ai=0
bi=0
while True:
    if len(a) <= ai and len(b) <= bi:
        break
    elif len(a) <= ai:
        _r=b[bi]
        bi+=1
    elif  len(b) <= bi:
        _r=a[ai]
        ai+=1
    elif a[ai:] < b[bi:]:
        _r=a[ai]
        ai+=1
    else:
        _r=b[bi]
        bi+=1
    if r+_r <= k:
        r+=_r
        c+=1
    else:
        break
print(c)

Submission status: Wrong Answer

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

for i in range(n+m):
    if len(a) == 0:
        k = k - b[0]
        if k >= 0:
            del b[0]
            ans += 1
        if k <= 0:
            print(ans)
            exit()
    elif len(b) == 0:
        k = k - a[0]
        if k >= 0:
            del a[0]
            ans += 1
        if k <= 0:
            print(ans)
            exit()
    elif a[0] > b[0]:
        k = k - b[0]
        if k >= 0:
            del b[0]
            ans += 1
        if k <= 0:
            print(ans)
            exit()
    else:
        k = k - a[0]
        if k >= 0:
            del a[0]
            ans += 1
        if k <= 0:
            print(ans)
            exit()
    #print(k)

Submission status: Wrong Answer

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

ans=0
now=0
acnt=0
bcnt=0
for i in range(n):
    if now+a[i]<=k:
        now+=a[i]
        acnt+=1
for i in range(m):
    if now+b[i]<=k:
        now+=b[bcnt]
        bcnt+=1
ans=acnt+bcnt
# print(now,ans,acnt,bcnt)
tmp=acnt
for i in range(tmp):
    now-=a[acnt-i-1]
    acnt-=1
    # print(now)
    while bcnt!=m and now+b[bcnt]<=k:
        now+=b[bcnt]
        bcnt+=1
    ans=max(ans,acnt+bcnt)
    # print(ans,acnt,bcnt)
for i in range(n):
    if now+a[i]<=k:
        now+=a[i]
        acnt+=1
ans=max(ans,acnt+bcnt)

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


ln = 0
lm = 0
ans = 0

while (k > 0):
    if (ln >= n):
        s = float("inf")
    else:
        s = a[ln]

    if (lm >= m):
        t = float("inf")
    else:
        t = b[lm]

    if (min(s, t) > k):
        break
    elif (s > t):
        k -= t
        lm += 1
    elif (t > s):
        k -= s
        ln += 1

print(ln+lm)

Submission status: Wrong Answer

Solution code:
def _main(N, M, K, A, B):
    sum_k = 0.0
    a_index = 0
    A_len = len(A)
    b_index = 0
    B_len = len(B)
    while sum_k < K:
        current_a = A[a_index] if a_index < A_len else None
        current_b = B[b_index] if b_index < B_len else None
        if current_a is None and current_b is None:
            break

        has_a = current_b is None and current_a is not None
        has_b = current_b is not None and current_a is None
        if has_a:
            if K < sum_k + current_a:
                break
            sum_k += current_a
            a_index += 1
        elif has_b:
            if K < sum_k + current_b:
                break
            sum_k += current_b
            b_index += 1
        elif current_a < current_b:
            if K < sum_k + current_a:
                break
            sum_k += current_a
            a_index += 1
        else:
            if K < sum_k + current_b:
                break
            sum_k += current_b
            b_index += 1

    print(a_index + b_index)


if __name__ == "__main__":
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    _main(N, M, K, A, B)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations

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

    time = 0
    res = 0

    while True:
        if len(A) != 0:
            tmp1 = A[0]
        else:
            tmp1 = 10 ** 10
        
        if len(B) != 0:
            tmp2 = B[0]
        else:
            tmp2 = 10 ** 10
        
        if tmp1 == 10 ** 10 and tmp2 == 10 ** 10:
            break
        elif tmp1 <= tmp2:
            tmp_time = A.popleft()
            time += tmp_time
            res += 1
        else:
            tmp_time = B.popleft()
            time += tmp_time
            res += 1
        
        if time > K:
            time -= tmp_time
            res -= 1
            break
    
    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
from bisect import bisect_right

def main():
    N, M, K = map(int, readline().rstrip().split())
    A = list(map(int, readline().rstrip().split()))
    B = list(map(int, readline().rstrip().split()))

    a_acc, b_acc = A[:], B[:]
    for i in range(1, N):
        a_acc[i] += a_acc[i-1]
    
    for i in range(1, M):
        b_acc[i] += b_acc[i-1]
    
    res = 0
    for i, a in enumerate(a_acc):
        if a >= K:
            break
        left = K - a
        j = bisect_right(b_acc, left)
        res = max(res, i + 1 + j)
    
    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

time = 0
i,j = 0,0
res = 0
while i < n and j < m:
    # print(str(i) +'  '+str(j) +'  '+str(time))
    read = min(arr[i],brr[j])
    if (read == arr[i]):
        if time + arr[i] <= k:
            time += arr[i]
            i += 1
            res += 1
            
        else:
            break
    else:
        if time + brr[j] <= k:
            res += 1
            time += brr[j]
            j += 1
        else:
            break
while i < n:
    if time + arr[i] <= k:
        res += 1
        time += arr[i]
        i += 1
    else:
        break

while j < m:
    if time + brr[j] <= k:
        res += 1
        time += brr[j]
        j += 1
    else:
        break

print(res)

Submission status: Wrong Answer

Solution code:
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
inf = float("inf") # 無限

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

a = list(map(int,input().split()))
b = list(map(int,input().split()))

time = 0
count = 0

while True:
    if len(a) == len(b) == 0:
        break
    elif len(a) == 0:
        temp = b.pop(0)
    elif len(b) == 0:
        temp = a.pop(0)
    elif a[0] < b[0]:
        temp = a.pop(0)
    else:
        temp = b.pop(0)
    time += temp
    if k < time:
        break
    else:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque
from sys import stdin
input = stdin.readline


def main():
  N, M, K = list(map(int, input().split()))
  A = deque(list(map(int, input().split())))
  B = deque(list(map(int, input().split())))
  A.append(float('inf'))
  B.append(float('inf'))

  num_book = 0

  while (len(A) > 1 or len(B) > 1):
    if A[0] < B[0]:
      K -= A[0]
      A.popleft()
    else:
      K -= B[0]
      B.popleft()

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

  print(num_book)


if(__name__ == '__main__'):
  main()

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

aa = a.pop(0)
bb = b.pop(0)

while True:
    if aa < bb:
        time += aa
        if len(a) > 0:
            aa = a.pop(0)
        else:
            aa = 10000000000
    else:
        time += bb
        if len(b) > 0:
            bb = b.pop(0)
        else:
            bb = 10000000000
    
    if time <= k:
        res += 1
    else:
        break
print(res)

Submission status: Wrong Answer

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

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

arr = []
while(len(a)!=0 and len(b)!=0):
  if a[0]<b[0]:
    arr.append(a[0])
    a.pop(0)
  elif b[0]<a[0]:
    arr.append(b[0])
    b.pop(0)

if len(a)==0: arr.extend(b)
else: arr.extend(a)
  
time = 0
cnt = 0
for i in arr:
  time += i
  if time<=k: cnt+=1
  else: break
print(cnt)

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

while(sum <= k):

    if len(a) == 0 and len(b) == 0:
        break

    else:

        if len(a) != 0 and len(b) == 0:
            sum += a[0]
            ans += 1
            a.pop(0)

        elif len(a) == 0 and len(b) != 0:
            sum += b[0]
            ans += 1
            b.pop(0)

        elif a[0] >= b[0]:
            sum += b[0]
            ans += 1
            b.pop(0)

        else:
            sum += b[0]
            ans += 1
            b.pop(0)

if ans == 1 and k < sum:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

A = []
B = []
A = deque(int(a) for a in input().split())
B = deque(int(a) for a in input().split())

count = 0
time = 0
while time < k:
    if len(A) == 0:
        if len(B) == 0:
            break
        else:
            t = B.popleft()
    else:
        if len(B)>0:
            if A[0] > B[0]:
                t = B.popleft()
            else:
                t = A.popleft()
        else:
            t = A.popleft()
    if time + t > k:
        break
    else:
        count += 1
        time += t

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] * 199999
b += [0] * 199999
c = 0
ctm = 0
t = 0
for i in range(n + m):
    if a[0] >= b[0]:
        t = b.pop(0)
    else:
        t = a.pop(0)
    if ctm + t < k:
        ctm += t
        c += 1
    else:
        break
print(c)

Submission status: Wrong Answer

Solution code:
INF = 10**9 + 1

N, M, K = map(int, input().split())
A = list(map(int, input().split())) + [INF]
B = list(map(int, input().split())) + [INF]

Ac = 0
Bc = 0
temp = K

while temp >= A[Ac] or temp >= B[Bc]:
  if Ac < N and Bc < M:
    if A[Ac] <= B[Bc]:
      temp -= A[Ac]
      Ac += 1
    else:
      temp -= B[Bc]
      Bc += 1
  elif Ac < N and Bc == M:
    temp -= A[Ac]
    Ac += 1      
  elif Ac == N and Bc < M:
    temp -= B[Bc]
    Bc += 1
  else:
    break
  
print(Ac+Bc)

Submission status: Wrong Answer

Solution code:
import math
from collections import Counter

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

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

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

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

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

ans = 0
now = 0

while True:
  if len(A) == 0 and len(B) == 0:
    break
 
  if len(A) == 0:
    now = now + B.pop(0)
  elif len(B) == 0:
    now = now + A.pop(0)
  elif len(A) > 0 and len(B) > 0:
    if A[0] > B[0]:
      now = now + B.pop(0)
    else:
      now = now + A.pop(0)
  ans = ans + 1
  if now > K:
    ans = ans - 1
    break;
  elif now == K:
    break;

print(ans)

Submission status: Wrong Answer

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

a = list(map(int, input().split()))
b = list(map(int, input().split()))

a_index = 0
b_index = 0

total_time = 0
ans = 0

while total_time <= k:
    if a_index >= len(a) and b_index >= len(b):
        ans += 1
        break
    elif a_index >= len(a):
        total_time += b[b_index]
        b_index += 1
        ans += 1
        continue
    elif b_index >= len(b):
        total_time += a[a_index]
        a_index += 1
        ans += 1
        continue

    if a[a_index] <= b[b_index]:
        total_time += a[a_index]
        a_index += 1
        ans += 1
    else:
        total_time += b[b_index]
        b_index += 1
        ans += 1

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

time = 0
count = 0
for _ in range(n + m):
    if len(a) > 0 and len(b)>0:
        if a[0] < b[0]:
            time += a[0]
            a = a[1:]
        else:
            time += b[0]
            b = b[1:]
    elif len(a) == 0 and len(b) > 0:
        time += b[0]
        b = b[1:]
    elif len(b) == 0 and len(a) > 0:
        time += a[0]
        a = a[1:]
    if time > k:
        break
    else:
        count += 1
        
        
print(count)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
x=[int(x) for x in input().split()]
y=[int(x) for x in input().split()]
c=0
cost=0
for i in range(n):
    if i<n and cost<k and cost+x[i]<=k :
        cost+=x[i]
        c+=1
    if i<m and  cost<k and cost+y[i]<=k:
        cost+=y[i]
        c+=1
i+=1
if m>n:
    while(i<(m)):
        if cost+y[i]<=k and cost<k:
            cost+=y[i]
            c+=1
        i+=1
print(c)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int, input().split())
A=list(map(int,input().split()))
A=sorted(A+list(map(int,input().split())))
cnt=0
time=0
for i in range(len(A)):
  if time+A[i]>k:
    break;
  else:
    time+=A[i]
    cnt+=1
print(cnt)

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 collections import deque
As=deque(As)
Bs=deque(Bs)
ans=0
inf=100000000000000000000000000000000000
while k>=0:
    try:
        a=As.popleft()
    except:
        a=inf
    try:
        b=Bs.popleft()
    except:
        b=inf
    if a>b:
        k-=b
        As.appendleft(a)
    else:
        k -=a
        Bs.appendleft(b)
    ans+=1
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()))
r=0
t=0
m_i=0
n_i=0
m+=-1
n+=-1
for i in range(m+n+2):
  #print(n_i)
  a_i=a[n_i]
  b_i=b[m_i]
  if (a_i>b_i):
    m_i+=1
    t+=b_i
    m_i=min(m_i,m)
  else:
    n_i+=1
    t+=a_i
    n_i=min(n_i,n)
  if t>k:
    break
  r+=1
print(r)