Problem:


Score : 300 points

Problem Statement

We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.

It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).

Consider the following action:

Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.

How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

Output

Print an integer representing the maximum number of books that can be read.

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

In this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd books from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st, 2-nd, 3-rd, 4-th books from the top on Desk B, respectively.

We can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.

Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.

Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.

Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000

Sample Output 3

0

Watch out for integer overflows.



Sample input:
3 4 240
60 90 120
80 150 80 150


Sample output:
3

Submission status: Wrong Answer

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

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

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

for i in range(N+M):
    if A_count >= N and B_count >= M:
        break

    print(A_count, B_count)
    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
    else:
        if A[A_count+1] < B[B_count+1]:
            time -= A[A_count]
            if time < 0:
                break
            A_count += 1
            ans += 1
        else:
            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:
import math
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

T = 0
ans = 0

while ((K-T) >= A[0]) or ((K-T) >= B[0]):
    if (len(A) == 0) and (len(B) != 0):
        T += B[0]
        ans += 1
        B.pop(0)
    elif (len(A) != 0) and (len(B) == 0):
        T += A[0]
        ans += 1
        A.pop(0)
    else:
        if A[0]<B[0]:
            T += A[0]
            ans += 1
            A.pop(0)
        else:
            T += B[0]
            ans += 1
            B.pop(0)
            
    if (len(A) ==0) and (len(B) == 0):
        break
    elif (len(A) == 0) and (len(B) != 0):
        A.append(math.inf)
    elif (len(A) != 0) and (len(B) == 0):
        B.append(math.inf)

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(10000000000)
b.append(10000000000)
ans = 0
t = 0
while t<k:
    if t+min(a[0],b[0])>k: break
    if a[0]<b[0]:
        t+=a[0]
        a.pop(0)
    else:
        t+=b[0]
        b.pop(0)
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
i1 = input().split(" ")
n = int(i1[0])
m = int(i1[1])
k = int(i1[2])
i2 = input().split(" ")  # desk A
i3 = input().split(" ")  # desk B

t = 0

def isWithinBudget(val, k):
    if k - val < 0:
        return False
    else:
        return True

for i in range(len(i2 + i3)):
    if len(i3) == 0 and len(i2) == 0:
        break
    elif len(i3) == 0:
        # pick form desk A
        val = int(i2.pop(0))
        if isWithinBudget(val, k):
            k -= val
            t += 1
        else:
            break
    elif len(i2) == 0:
        val = int(i3.pop(0))
        if isWithinBudget(val, k):
            k -= val
            t += 1
        else:
            break
    else:
        if int(i3[0]) >= int(i2[0]):
            # pick form desk A
            val = int(i2.pop(0))
            if isWithinBudget(val, k):
                k -= val
                t += 1
            else:
                break
        else:
            val = int(i3.pop(0))
            if isWithinBudget(val, k):
                k -= val
                t += 1
            else:
                break

    if k < 0:
        break
print(t)

Submission status: Wrong Answer

Solution code:
import sys
import os
import itertools
import numpy as np
from collections import deque

def main():
    if os.getenv("ENV")=='LOCAL':
        sys.stdin = open(os.path.dirname(__file__)+'/input.txt', 'r')

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

    lA=len(A)-1
    Ap=0
    Bp=0
    n=0
    t=0

    for i in range(len(A)): #Aは可能な限り足す
        if t+A[i]>K:
            break
        Ap=i
        t+=A[i]
        n+=1
    for i in range(len(B)):
        if t+B[i]>K:
            break
        Bp=i
        t+=B[i]
        n+=1

    max=n #読める本の最大値
    # print(max)
    for i in range(len(A)):
        n-=1
        t-=A[lA-i]
        for j in range(Bp,len(B)):
            if t+B[j]>K:
                break
            Bp=j
            t+=B[j]
            n+=1
        # print(n)
        if max<n:
            max=n

    print(max)

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

sA = sum(A)
sB = sum(B)

def countmax(A, N, K):
    sA_ = 0
    for i in range(N):
        sA_ += A[i]
        if sA_ > K:
            return i
    return N

# Dont need count
if sA + sB <= K:
    print(N + M)
    exit(0)

## Aの全読み VS Bの全読みにならない？
## Aの全読み
if sA <= K:
    Ayomi = N + countmax(B, M, K - sA)
else:
    ayonda = countmax(A, N, K)
    Ayomi = countmax(B, M, K-sum(A[:ayonda]))+ayonda

## Bの全読み
if sB <= K:
    Byomi = M + countmax(A, N, K - sB)
else:
    byonda = countmax(B, M, K)
    Byomi = countmax(A, N, K-sum(B[:byonda]))+byonda

print(max(Ayomi,Byomi))

Submission status: Wrong Answer

Solution code:
n, m , has_time = [int(x) for x in input().split()]
nb = [int(x) for x in input().split()]
mb = [int(x) for x in input().split()]
cost = []
for i in range(max(n, m)):
    if i < n:
        if i < m:
            curr = min(nb[i], mb[i])
        else:
            curr = nb[i]
    else:
        if i < m:
            curr = mb[i]
    if len(cost):
        curr += cost[-1]
    cost.append(curr)
can_do = 0
for i in cost:
    if i <= has_time:
        can_do += 1
    else:
        break
print(can_do)

Submission status: Wrong Answer

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

counter = 0  # min
idx_a = 0
idx_b = 0

for _ in range(n+m):
    if idx_a == n:
        counter += b[idx_b]
        idx_b += 1
    elif idx_b == m:
        counter += a[idx_a]
        idx_a += 1
    elif a[idx_a] <= b[idx_b]:
        counter += a[idx_a]
        idx_a += 1
    elif a[idx_a] > b[idx_b]:
        counter += b[idx_b]
        idx_b += 1
    if counter > k:
        print(idx_a+idx_b-1)
        break
else:
    print(idx_a+idx_b)

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.extend(B)
AB = sorted(A, reverse=True)


for ab in AB:
    if sum(AB) <= K:
        break
    AB.remove(ab)
print(len(AB))

Submission status: Wrong Answer

Solution code:
import sys
import math 
from collections import deque

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

i=0
j=0
ans=0
tmp=0
re=0
while True:
    if i==n and j==m:
        break
    elif i==n:
        re=b[j]
        j+=1
    elif j==m:
        re=A[i]
        i+=1
    else:
        q=A[i]
        u=b[j]
        re=min(q,u)
        if re ==q:
            i+=1
        else:
            j+=1

    tmp+=re
    if i+j==n+m:
        ans+=1
        print(ans)
        sys.exit()
    elif tmp>=k:
        print(ans)
        sys.exit()
    else:
        
        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()))

A.append(10**10)
B.append(10**10)

A_ruiseki = [A[0]]
for i in range(1, n):
    if A_ruiseki[i-1]+A[i] <=k :
        A_ruiseki.append(A_ruiseki[i-1]+A[i])
    else:
        break

ans = 0

for i in range(len(A_ruiseki)):
    time = A_ruiseki[i]
    if time > k:
        continue
    cnt_b = 0
    while cnt_b < m:
        if time + B[cnt_b] <= k:
            time += B[cnt_b]
            cnt_b += 1
        else:
            break

    ans = max(ans, (i+1) + cnt_b)

print(ans)

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

# merge
books = [0] * (N+M)
ai = 0
bi = 0
for i in range(N+M):
    if ai == N:
        books[i] = B_list[bi]
        bi += 1
        continue
    elif bi == M:
        books[i] = A_list[ai]
        ai += 1
        continue

    if A_list[ai] <= B_list[bi]:
        books[i] = A_list[ai]
        ai += 1
        continue
    else:
        books[i] = B_list[bi]
        bi += 1
        continue

k = 0
cnt = 0
for book in books:
    k += book
    if k > K:
        break
    cnt += 1
print(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(" ")))

que = list()

flag = True
val = 0

while flag:
    if len(A) > 0 and len(B) > 0:
        if A[0] < B[0]:
            val = A.pop(0)
        else:
            val = B.pop(0)
    elif len(A) == 0 and len(B) == 0:
        flag = False
        break
        val = B.pop(0)
    elif len(A) == 0:
        val = B.pop(0)
    elif len(B) == 0:
        val = A.pop(0)

    if sum(que) + val <= K:
        que.append(val)
    else:
        flag = False
        break


print(len(que))

Submission status: Wrong Answer

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

i, j = 0, 0
total = 0
for _ in range(n + m):
  # print(i, j, m, n)
  if j == m:
    total += a[i]
    i += 1
  elif i == n:
    total += b[j]
    j += 1
  elif a[i] < b[j]:
    total += a[i]
    i += 1
  else:
    total += b[j]
    j += 1
  if total > k:
    print(i + j - 1)
    exit()
print(i + j)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))
'''
N, M , lim = mi()

A = li()
B = li()

A += [10**9+1]
B += [10**9+1]
ind_a = 0 
ind_b = 0

cnt = ans = 0

while True:
    if A[ind_a] > B[ind_b]:
        if cnt + B[ind_b] <= lim:
            ans += 1
            cnt += B[ind_b]
            if ind_b != M:
                ind_b += 1
        else:
            break

    elif A[ind_a] < B[ind_b]:
        if cnt + A[ind_a] <= lim:
            ans += 1
            cnt += A[ind_a]
            if ind_a != N:
                ind_a += 1
        else:
            break

    else:
        if ind_a == N and ind_b == M:
            break
        elif ind_a == N:
            if cnt + B[ind_b] <= lim:
                ans += 1
                cnt += B[ind_b]
                if ind_b != M:
                    ind_b += 1
            else:
                break
        elif ind_b == M:
            if cnt + A[ind_a] <= lim:
                ans += 1
                cnt += A[ind_a]
                if ind_a != N:
                    ind_a += 1
            else:
                break
        else:
            if A[ind_a+1] >= B[ind_b+1]:
                if cnt + B[ind_b] <= lim:
                    ans += 1
                    cnt += B[ind_b]
                    if ind_b != M:
                        ind_b += 1
                else:
                    break
            else:
                if cnt + A[ind_a] <= lim:
                    ans += 1
                    cnt += A[ind_a]
                    if ind_a != N:
                        ind_a += 1
                else:
                    break

print(ans)
'''
N, M , lim = mi()

A = li()
B = li()

A = [0] + list(accumulate(A))
B = list(accumulate(B))
ans = 0
for i in range(N+1):
    ind = bisect.bisect_right(B, max(lim-A[i], 0))
    #print(i, ind)
    if ind > 0:
        ans = max(ans, ind + i)

print(ans)

Submission status: Wrong Answer

Solution code:
x = input().split()
N = int(x[0])
M = int(x[1])
K = int(x[2])
T = 0
N = 0
A = input().split()
B = input().split()
A.append(10000000000)
B.append(10000000000)

while K > T:
    if int(A[0]) <= int(B[0]):
        if T + int(A[0]) > K:
            break
        T += int(A[0])
        N += 1
        del A[0]

    else:
        if T + int(B[0]) > K:
            break
        T += int(B[0])
        N += 1

        del B[0]
print(N)

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()))
max = 10 ** 9 + 1
time = 0
ans = 0
a = 0
b = 0

for i in range(n + m):
    if a_list[a] < b_list[b]:
        time += a_list[a]
        a += 1
    else:
        time += b_list[b]
        b += 1

    if time > k:
        break
    else:
        ans += 1

    if a >= n:
        a_list.append(max)
    if b >= m:
        b_list.append(max)

print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
    from bisect import bisect_right
    n,m,k=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    A,B=[],[]
    x=0
    for i in range(n):
        x+=a[i]
        A.append(x)
    for j in range(m):
        x+=b[j]
        B.append(x)
    ai=bisect_right(A,k)
    ans=0
    for i in range(ai,-1,-1):
        if ai==0:
            bi=bisect_right(B,k)
        else:
            bi=bisect_right(B,k-a[i-1])
        if i+bi==0:
            continue
        else:
            ans=max(ans,i+bi+1)
    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
from collections import deque

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

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

while k >= count and l >= ans:
    if la > ac and lb > bc:
        if k >= count + min(a[0], b[0]):
            count += min(a[0], b[0])
            ans += 1
            if b[0] >= a[0]:
                a.popleft()
                ac += 1
            else:
                b.popleft()
                bc += 1
        else:
            break
    elif la == ac and lb > bc:
        if k >= count + b[0]:
            count += b[0]
            ans += 1
            b.popleft()
            bc += 1
        else:
            break
    elif lb == bc and la > ac:
        if k >= count + a[0]:
            count += a[0]
            ans += 1
            a.popleft()
            ac += 1
        else:
            break
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

a_i = 0
b_i = 0
#print("a_i =",a_i,"/ b_i =",b_i,"/ K =",K)

while( K>0 and count<(N+M) ):
  
  if ( a_i < N and b_i < M ):
    if ( A[a_i] < B[b_i] ):
      K -= A[a_i]
      a_i += 1
      count += 1
    else:
      K -= B[b_i]
      b_i += 1
      count += 1
  else:
    if ( a_i < N ):
      K -= A[a_i]
      a_i += 1
      count += 1
    else:
      K -= B[b_i]
      b_i += 1
      count += 1

  #print("a_i =",a_i,"/ b_i =",b_i,"/ K =",K)


if (K<0):
  print(count-1)
else:
  print(count)

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

arr = a + b

arr.sort()

mod = 10**9 + 7
c = 0
s = 0
for el in arr:
  s = (s%mod + el%mod)%mod
  
  if s<=k:
    c += 1
  else:
    break
print(c)

Submission status: Wrong Answer

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

ASUM = [AN[0]]
for i in range(len(AN)):
    if i == 0: continue
    ASUM.append(ASUM[-1] + AN[i])
BSUM = [BN[0]]
for i in range(len(BN)):
    if i == 0: continue
    BSUM.append(BSUM[-1] + BN[i])

maxNM = max(len(AN), len(BN))
dp = [0]
aindex = 0
bindex = 0
for i in range(len(AN)+len(BN)):
    if len(AN) <= aindex:
        dp.append(dp[-1]+BN[bindex])
        bindex += 1
        continue
    if len(BN) <= bindex:
        dp.append(dp[-1] + AN[aindex])
        aindex += 1
        continue
    if AN[aindex] < BN[bindex]:
        dp.append(dp[-1] + AN[aindex])
        aindex += 1
    else:
        dp.append(dp[-1] + BN[bindex])
        bindex += 1
    if dp[-1] > K:
        dp = dp[:-1]
        break
print(len(dp)-1)

Submission status: Wrong Answer

Solution code:
import collections

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

Aq = collections.deque(A)
Bq = collections.deque(B)

ans = 0
sumt = 0
flag = True
while len(Aq) > 0 and len(Bq) > 0:
    if Aq[0] <= Bq[0]:
        if sumt + Aq[0] > K:
            flag = False
            break
        sumt += Aq.popleft()
        ans += 1
    else:
        if sumt + Bq[0] > K:
            flag = False
            break
        sumt += Bq.popleft()
        ans += 1
if flag:
    if len(Aq) > 0:
        while len(Aq) > 0:
            if sumt + Aq[0] > K:
                break
            sumt += Aq.popleft()
            ans += 1
    else:
        while len(Bq) > 0:
            if sumt + Bq[0] > K:
                break
            sumt += Bq.popleft()
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
k=int(input().split()[-1])
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
while len(a+b)>0:
	if len(b)==0 or len(a)>0 and a[0]<b[0]:
		c+=[a.pop(0)]
	else:
		c+=[b.pop(0)]
	if sum(c)>k:
		c.pop();break
print(len(c))

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, M, K = LI()
    A = LI()
    B = LI()
    i = 0
    j = 0
    cnt = 0
    while i < N and j < M:
        if A[i] < B[j]:
            K -= A[i]
            cnt += 1
            i += 1
        else:
            K -= B[j]
            cnt += 1
            j += 1
        if K < 0:
            cnt -= 1
            print(cnt)
            return

    if i == N and j == M:
        print(cnt)
        return

    if i < N and j == M:
        while i < N:
            K -= A[i]
            if K < 0:
                print(cnt)
                return
            i += 1
            cnt += 1
    elif i == N and j < M:
        while j < M:
            K -= B[j]
            if K < 0:
                print(cnt)
                return
            j += 1
            cnt += 1
    else:
        pass

    print(cnt)



main()

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 = [10000000000]+list(reversed(A)) 
B = [10000000000]+list(reversed(B))

total = 0
while K>0:
  if min(A[-1],B[-1])<=K:
    if A[-1]<B[-1]:
      K -= A.pop()
    else:
      K -= B.pop()
    total += 1
    continue
  else:
    break

print(total)

Submission status: Wrong Answer

Solution code:
def main(N, M, K, A, B):
    lst = A + B
    lst.sort()
    len_lst = N + M

    k = K   # 制限時間

    i = 0
    while k >= 0 and i != len_lst:
        k -= lst[i]
        i += 1

    if i == len_lst:
        print(i)
    else:
        print(i-1)


if __name__ == '__main__':
    N, M, K = list(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:
import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right,bisect
n,m,k=map(int,stdin.readline().split())
a=list(map(int,stdin.readline().split()))
b=list(map(int,stdin.readline().split()))
prea=[]
ans=0
for i in a:
    ans+=i 
    prea.append(ans)
final=0
temp=0
for i in range(m):
    temp+=b[i]
    if(temp>k):
        break
    temp2=bisect(prea,k-temp)
    final=max(final,temp2+i+1)
print(final)

Submission status: Wrong Answer

Solution code:
NMK=input().split(" ")
N=int(NMK[0])
M=int(NMK[1])
K=int(NMK[2])

def list2int(List):
    out=[]
    for i in range(len(List)):
        out.append(int(List[i]))
    return out

A=list2int(input().split(" "))
B=list2int(input().split(" "))

time=0
A_idx=0
B_idx=0
cnt=0
while(True):
    if(A_idx<len(A) and B_idx<len(B)):
        if(A[A_idx]<B[B_idx]):
            time+=A[A_idx]
            A_idx+=1
        elif(A[A_idx]==B[B_idx]):
            flag=""
            a=A_idx
            b=B_idx
            while(len(flag)<0):
                if(a+1<len(A) and b+1<len(B)):
                    if(A[a+1]<B[b]):
                        flag="A"
                        break
                    elif(B[b+1]<A[a]):
                        flag="B"
                        break
                    elif(A[a]==B[b]):
                        a+=1
                        b+=1
                        continue
                elif(a+1>=len(A) and b+1<len(B)):
                    flag="B"
                elif(a+1<len(A) and b+1>=len(B)):
                    flag="A"
                else:
                    break
            if(flag=="A"):
                time+=A[A_idx]
                A_idx+=1
            else:
                time+=B[B_idx]
                B_idx+=1
        else:
            time+=B[B_idx]
            B_idx+=1
    elif(A_idx>=len(A) and B_idx<len(B)):
        time+=B[B_idx]
        B_idx+=1
    elif(B_idx>=len(B) and A_idx<len(A)):
        time+=A[A_idx]
        A_idx+=1
    else:
        break
    if(time>K):
        break
    else:
        cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))+[10**9+1]*m
b = list(map(int,input().split()))+[10**9+1]*n
Sum = 0
ans = 0
a_i = 0
b_i = 0
N = n+m

for i in range(N):
    if a[a_i] < b[b_i]:
        Sum += a[a_i]
        a_i += 1
    else:
        Sum += b[b_i]
        b_i += 1
    if Sum > k:
        ans = i
        break
else:
    ans = 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()))
t_a=[]
t_b=[]
l=0
for i in range(N):
  l+=A[i]
  t_a.append(l)
l=0
for i in range(M):
  l+=B[i]
  t_b.append(l)
def bi_re(i):
  x=t_a[i]
  if x>K:
    return 0
  x=K-x
  l=0;r=M-1
  while l<=r:
    m=(l+r)//2
    q=t_b[m]
    if q==x:
      return m+i+2
    elif q<x:
      l=m+1
    else:
      r=m-1
  for j in range(max(0,m-2),min(M-1,m+2)):
    if t_b[j]<=x:
      r=j  
  return r+i+2
  
  
  
ans=0
for i in range(N):
  ans=max(bi_re(i),ans)
print(ans)

Submission status: Wrong Answer

Solution code:
#関数リスト
import sys
import numpy
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n, k , m = MI()
a = numpy.cumsum(LI())
b = numpy.cumsum(LI())
a = a[a<=m]
b = b[b<=m]

result = -1
for i in range(len(a)):
    tempa = a[i]
    tempb = len(b[b<=m-tempa])
    if result < i+tempb:
        result = i+tempb
print(result+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()))

ans = 0
a_ind = 0
b_ind = 0
while k > 0:
    if n > a_ind and m > b_ind:
        if a[0] < b[0]:
            if k >= a[a_ind]:
                k -= a[a_ind]
                a_ind += 1
                ans += 1
            else:
                break
        else:
            if k >= b[b_ind]:
                k -= b[b_ind]
                b_ind += 1
                ans += 1
            else:
                break
    elif n > a_ind and m == b_ind:
        if k >= a[a_ind]:
            k -= a[a_ind]
            a_ind += 1
            ans += 1
        else:
            break
    elif n == a_ind and m > b_ind:
        if k >= b[b_ind]:
            k -= b[b_ind]
            b_ind += 1
            ans += 1
        else:
            break
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

n, m, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a.reverse()
b.reverse()
ans = 0

for i in range(n + m):
    
    if a[-1] > b[-1]:
        cost = b.pop(-1)
    else:
        cost = a.pop(-1)
    
    k -= cost
    if k < 0:
        break
    if len(a) == 0:
        a.append(float('inf'))
    elif len(b) == 0:
        b.append(float('inf'))
    
    ans += 1

print(ans)

Submission status: Wrong Answer

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

C =A+B
C.sort()

min = C[0]
cnt= 0

if sum(C) <= K:
  print(len(C))
else:
  for i in range(1,len(C)):
    while min < K:
      min +=C[i]
      cnt+=1
      break
  print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import deque
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ad = deque(a)
ad.append(float('inf'))
bd = deque(b)
bd.append(float('inf'))
count = 0
while True:
    k = k - min(ad[0],bd[0])
    if k >= 0:
        if ad[0] > bd[0]:
            bd.popleft()
        else:
            ad.popleft()
        count += 1
    else:
        break
print(count)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
time = 0
i = 0
j = 0
count = 0
flaga = 1
flagb = 1
while time <= k:
    if flaga == 1 and flagb == 1:
        if a[i] > b[j]:
            time += b[j]
            count += 1

            if j == m-1:
                flagb = 0
            else:
                j += 1
        else:
            time += a[i]
            count += 1
            if i == n-1:
                flaga = 0
            else:
                i += 1
    elif flaga == 1 and flagb == 0:
        time += a[i]
        count += 1
        if i == n-1:
            flaga = 0
        else:
            i += 1
    elif flagb == 1 and flaga == 0:
        time += b[j]
        count += 1
        if j == m-1:
            flagb = 0
        else:
            j += 1
    elif flaga == 0 and flagb == 0:
        break
if time <= k:
    print(count)
else:
    print(count-1)

Submission status: Wrong Answer

Solution code:
import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ca = A[:]
cb = B[:]

for i in range(N-1):
  ca[i+1] += ca[i]
for i in range(M-1):
  cb[i+1] += cb[i]

ans = 0
for i in range(N):
  if ca[i] <= K:
    idx = bisect.bisect_right(cb, K-ca[i])
  else:
    continue
  
  ans = max(ans, i+idx+1)


for i in range(M):
  if cb[i] <= K:
    idx = bisect.bisect_right(cb, K-cb[i])
  else:
    continue
  
  ans = max(ans, i+idx+1)
print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
costA=list(map(int,input().split()))
costB=list(map(int,input().split()))
time=0
count=0
while time<=K:
    if len(costA)==0:
        costA.append(float("inf"))
    if len(costB)==0:
        costB.append(float("inf"))
    time+=min(costA[0],costB[0])
    count+=1
    if min(costA[0],costB[0])==costA[0]:
        del costA[0]
    else:
        del costB[0]
print(count-1)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
alis = list(map(int, input().split())) + [10000000000000]
blis = list(map(int, input().split())) + [10000000000000]
su = 0
a = 0
b = 0
if sum(alis) + sum(blis) < k:
  print(len(alis) + len(blis))
  quit()
  
while su <= k:
  if alis[a] > blis[b]:
    su += blis[b]
    b += 1
  else:
    su += alis[a]
    a += 1
    
print(a + b - 1)

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

#a = a[::-1]
#b = b[::-1]

ai = 0
bi = 0

dp = [0 for i in range(M+N+1)]
#dp[0] = sum(a) + sum(b)

for i in range(1, N+M+1):
    if ai == N:
        res = b[bi]
        bi += 1
    elif bi == M:
        res = a[ai]
        ai += 1
    elif a[ai] < b[bi]:
        res = a[ai]
        ai += 1
    else:
        res = b[bi]
        bi += 1
    dp[i] = dp[i-1] + res

#dp = dp[::-1]
#print(dp)

import bisect
print(bisect.bisect_right(dp, K)-1)

Submission status: Wrong Answer

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

a_list=[int(i) for i in input().split()]
b_list=[int(i) for i in input().split()]
#print(a_list)
#print(b_list)

t=0
count=0

while t<=k:
    if a_list==[] and b_list==[]:
        count+=1
        break
    
    elif a_list==[]:
        t+=b_list[0]
        del b_list[0]
        count+=1
        
    elif  b_list==[]:
        t+=a_list[0]
        del a_list[0]
        count+=1
        
    elif a_list[0] <  b_list[0]:
        t+=a_list[0]
        del a_list[0]
        count+=1
        
    else:
        t+=b_list[0]
        del b_list[0]
        count+=1
    
    
    
print(count-1)