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 = 0
book = 0
stop = 0
for i in range(N):
    if time + A[i] <= K:
        time += A[i]
        book += 1
        stop = i

max_book = book 
flag = True
for i in range(M):
    if time + B[i] <= K:
        time += B[i]
        book += 1
        max_book = max(max_book, book)
    else:
        while True:
            if stop > 0:
                time -= A[stop]
                stop -= 1
                book -= 1
                if time + B[i] <= K:
                    break
            else:
                flag = False
                break
    if flag:
        break

print(max_book)

Submission status: Wrong Answer

Solution code:
from collections import deque
n,m,k = map(int, input().split())
a = deque(map(int, list(input().split())))
b = deque(map(int, list(input().split())))
t = 0
c = 0
while k <= 1000000000 and n <= 200000 and m <= 200000:
    if c < n+m:
        if len(b) == 0 and t + a[0] <= k:
            t = t + a[0]
            a.popleft()
            c = c + 1
        elif len(a) == 0 and t + b[0] <= k:
            t = t + b[0]
            b.popleft()
            c = c + 1
        elif len(a) > 0 and len(b) > 0:
            if a[0] <= b[0] and a[0] <= 1000000000 and b[0] <= 1000000000 and t + a[0] <= k:
                t = t + a[0]
                a.popleft()
                c = c + 1
            elif a[0] > b[0] and a[0] <= 1000000000 and b[0] <= 1000000000 and t + b[0] <= k:
                t = t + b[0]
                b.popleft()
                c = c + 1
            else:
                break
        else:
            break
    else:
        break
print(c)

Submission status: Wrong Answer

Solution code:
def INT():
    return int(input())

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

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

from itertools import combinations

N, M, K = MI()
A = LI()
B = LI()
s_A = sum(A)
s_B = sum(B)
i, j = 0, 0
ans = N + M

for k in range(1, N + M + 1):
    if s_A + s_B > K:

        if A[N - i - 1] >= B[M - j - 1]:
            if s_A >= s_B:
                s_A -= A[N - i - 1]
                i += 1
            else:
                s_B -= B[M - j - 1]
                j += 1

        else:
            if s_B >= s_A:
                s_B -= B[M - j - 1]
                j += 1
            else:
                s_A -= A[N - i - 1]
                i += 1

        ans -= 1
    
    else:
        break
        
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
from numpy import cumsum

n, m, k = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

cumA = cumsum(A)
cumB = cumsum(B)

if cumA[0] >= k:
    print(bisect_right(cumB, k))
    exit()

ans = 0

for idx_a, a in enumerate(cumA):
    if a >= k:
        break
    rem = k - a
    idx_b = bisect_right(cumB, rem)
    ans = max(ans, idx_a + 1 + idx_b)
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    INF = 10**18
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    a.append(INF)
    b.append(INF)
    ap = -1
    bp = -1

    cnt = 0
    now = 0
    for i in a:
        if now + i <= k:
            now += i
            cnt += 1
            ap += 1

    for i in b:
        if now + i <= k:
            now += i
            cnt += 1
            bp += 1
        elif i <= a[ap]:
            now = now - a[ap] + i

    print(cnt)

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()))
ans=0
for i in range(n):
  if sum(a[:i+1])>k:
    break
  elif sum(a[:i+1])+sum(b)<=k:
      if sum(a[:i+2])>k:
        ans=max(ans,i+m+1)
      else:
        continue
  else:  
    for j in range(m):
      if sum(a[:i+1])+sum(b[:j+1])<=k:
        continue
      else:
        ans=max(ans,i+j+1)
        break
print(ans)

Submission status: Wrong Answer

Solution code:
# 初期入力
from collections import deque
import sys
input = sys.stdin.readline
N,M,K = (int(i) for i in input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
dq_a =deque(A)
dq_b =deque(B)

#上から読む＝配列の前から読む
read_time =0
ans =0
a=dq_a.popleft()
b=dq_b.popleft()
for i in range(N+M):
    if a <=b :
        if read_time +a <=K:
            read_time +=a
            ans +=1
            if len(dq_a) >0:
                a =dq_a.popleft()
            else:
                a=10**9 +1
        else:
            break
    if a >=b:
        if read_time +b <=K:
            read_time +=b
            ans +=1
            if len(dq_b) >0:
                b =dq_b.popleft()
            else:
                b=10**9 +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()))

a_i = 0
b_i = 0
cnt = 0

while True:
    if a_i < n and b_i < m:
        if a[a_i] <= b[b_i]:
            k -= a[a_i]
            if k >= 0:
                cnt += 1
            a_i += 1
        
        else:
            k -= b[b_i]
            if k >= 0:
                cnt += 1
            b_i += 1

    else:
        if a_i == n:
            k -= b[b_i]
            if k >= 0:
                cnt += 1
            b_i += 1
            if b_i == m:
                break

        elif b_i == m:
            k -= a[a_i]
            if k >= 0:
                cnt += 1
            a_i += 1
            if a_i == n:
                break

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

sum_time = 0
count = 0

while sum_time<K:
    if not A and not B:
        break
    elif not A:
        sum_time+=B[0]
        B.pop(0)
    elif not B:
        sum_time+=A[0]
        A.pop(0)
    elif A[0] <= B[0]:
        sum_time+=A[0]
        A.pop(0)
    elif not A or A[0] >= B[0]:
        sum_time+=B[0]
        B.pop(0)
    count+=1
if sum_time>K:
    count-=1
print(count)

Submission status: Wrong Answer

Solution code:
def resolve():
    n, m, k = map(int, input().split())
    A = list(map(int, input().split())) 
    B = list(map(int, input().split()))
    
    ans = 0
    total = 0
    i = 0
    j = 0
    while True:
        if i < n:
            a = A[i]
        else:
            a = 10 ** 9
        
        if j < m:
            b = B[j]
        else:
            b = 10 ** 9
        total += min(a, b)
        if min(a,b) == a:
            i += 1
        else:
            j += 1
        if total > k:
            break
        else:
            ans += 1
    print(ans)
resolve()

Submission status: Wrong Answer

Solution code:
import collections as cs

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

A.append(K + 1)
B.append(K + 1)

print(A)

count = 0
time = 0
num = len(A) + len(B)

for i in range(num):
    if A[0] <= B[0]:
        if A[0] + time <= K:
            time += A.popleft()
            count += 1

    elif A[0] > B[0]:
        if B[0] + time <= K:
            time += B.popleft()
            count += 1

print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque

N, M, K = map(int, input().split())
alist = list(map(int, input().split()))
blist = list(map(int, input().split()))
aq = deque()
bq = deque()
res=0

for i in range(0,N):
  aq.append(alist[i])

for j in range(0,M):
  bq.append(blist[j])

while(0<K):
  if(len(aq)==0 and len(bq)==0):
    break
  elif(len(aq)==0):
    b=bq.popleft()
    res+=1
    K-=b
    if(K<0):
      res-=1
      break
  elif(len(bq)==0):
    a=aq.popleft()
    res+=1
    K-=a
    if(K<0):
      res-=1
      break
  else:
    a=aq.popleft()
    b=bq.popleft()
    if(a<b):
      res+=1
      K-=a
      if(K<0):
        res-=1
        break
      bq.appendleft(b)
    elif(b<a):
      res+=1
      K-=b
      if(K<0):
        res-=1
        break
      aq.appendleft(a)
    elif(a==b):
      res+=1
      K-=a
      if(K<0):
        res-=1
        break
      res+=1
      K-=b
      if(K<0):
        res-=1
        break
print(res)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

ans = 0 
time = 0 

while time <= k:
#    print('time =', time)
#    print('a =', a)
#    print('b =', b)

    if len(a) > 0 and len(b) > 0:
        if a[0] <= b[0]:
            time += a[0]
            ans += 1
            a.pop(0)
        else:
            time += b[0]
            ans += 1
            b.pop(0)

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

    elif len(a) > 0 and len(b) == 0:
        time += a[0]
        ans += 1
        a.pop(0)
    
    else:
        break

if time == k:
    print(ans)
else:
    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()))
sum = 0
count = 0
i = 0
j = 0
while 1:
    if i < n and j < m:
        if a[i] < b[j]:
            sum += a[i]
            if sum > k:
                print(count)
                exit()
            i += 1
            count += 1
        else:
            sum += b[j]
            if sum > k:
                print(count)
                exit()
            j += 1
            count += 1
    elif i == n and j == n:
        print(n + m)
        exit()
    elif i == n:
        sum += b[j]
        if sum > k:
            print(count)
            exit()
        j += 1
        count += 1
    else:
        sum += a[i]
        if sum > k:
            print(count)
            exit()
        i += 1
        count += 1

Submission status: Wrong Answer

Solution code:
from collections import deque

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

b_q = deque(b_list)
k_q = deque()

ans = 0

for a in a_list:
    if k - a >=0:
        k_q.append(a)
        k -= a
        ans += 1
while True:
    if b_q:
        b = b_q.popleft()
        if k - b >=0:
            k -= b
            ans += 1
        else:
            break
    else:
      break
el_num = len(k_q)
final_ans = ans
for i in range(el_num):
    ans -= 1
    k += k_q.pop()
    while b_q and True:
        if k - b_q[0] >= 0:
            ans += 1
            k -= b_q.popleft()
        else:
            break
    final_ans = max(final_ans, ans)
print(final_ans)

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

ma = (10 ** 9) + 1
A.append(ma)
B.append(ma)

i = 0
j = 0
ans = 0
while K - A[i] >= 0 or K - B[j] >= 0:
    if A[i] < B[j]:
        ans += 1
        K -= A[i]
        i += 1
    elif A[i] > B[j]:
        ans += 1
        K -= B[j]
        j += 1
    elif A[i] == B[j] and A[i + 1] < B[j + 1]:
        ans += 1
        K -= A[i]
        i += 1
    elif A[i] == B[j] and A[i + 1] > B[j + 1]:
        ans += 1
        K -= B[j]
        j += 1

print(ans)

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()]
need = 0
done = 0
while nb or mb:
    if nb and mb:
        if nb[0] < mb[0]:
            curr = nb.pop(0)
        else:
            curr = mb.pop(0)
    elif nb:
            curr = nb.pop(0)
    elif mb:
        curr = mb.pop(0)
    #print(need, curr)
    need += curr


    if need <= has_time:
        done += 1
    else:
        break
print(done)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import accumulate
input = sys.stdin.readline

N,M,K=map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
A_acc = list(accumulate(A))
B_acc = list(accumulate(B))
a = 0
b = 0
ans = 0
m = 0
while m < K:
    if a < N and b < M:
        if min(N,M) > max(a,b):
            if A_acc[max(a,b)] < B_acc[max(a,b)] and a < b:
                a,b = b,a
                m = A_acc[a]+B_acc[b] - A[a] - B[b]
            elif A_acc[max(a,b)] > B_acc[max(a,b)] and a > b:
                a,b = b,a
                m = A_acc[a] + B_acc[b] - A[a] - B[b]
        if A[a] < B[b] and A[a] <= K-m:
            m += A[a]
            a += 1
        elif A[a] >= B[b] and B[b] <= K-m:
            m += B[b]
            b += 1
        else:
            break
    elif a < N and A[a] <= K-m:
        m += A[a]
        a += 1
    elif b < M and B[b] <= K-m:
        m += B[b]
        b += 1
    else:
        break
print(a+b)

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

from itertools import accumulate
from collections import deque
A=deque(list(accumulate(A)))
B=deque(list(accumulate(B)))
A.appendleft(0)
B.appendleft(0)
ans1=0
for i in range(N+1):
    if A[i]>K:
        ans1=i
        break
else:
    ans1=N
ans2=0
ans3=0
for i in range(ans1):
    if ans1==1:
        while i+ans2<=M and A[ans1-i-1]+B[i+ans2]<=K:
            ans2+=1
        ans3=max(ans3,ans1+ans2-1)
    else:
        while i+ans2<=M and A[ans1-i]+B[i+ans2]<=K:
            ans2+=1
        ans3=max(ans3,ans1+ans2-1)
print(ans3)

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

n_A=0
n_B=0
time=0

while time <= K:
  if n_A < N:
    if n_B<M:
      if A[n_A]<B[n_B]:
        time+=A[n_A]
        if time <=K:
          n_A+=1
      else:
        time+=B[n_B]
        if time <=K:
          n_B+=1
    else: 
      time+=A[n_A]
      if time <=K:
        n_A+=1
  elif n_B <M:
    time+=B[n_B]
    if time <=K:
      n_B+=1
  else:
    break

print(n_A+n_B)

Submission status: Wrong Answer

Solution code:
line = input().split()
n, m, k = int(line[0]), int(line[1]), int(line[2])
line = input().split()
a = [None] * n
for i in range(n):
    a[i] = int(line[i])
line = input().split()
b = [None] * m
for i in range(m):
    b[i] = int(line[i])

time = [[0 for j in range(n+1)] for i in range(m+1)]
for i in range(1,n+1):
    time[0][i] = time[0][i-1] + a[i-1]
for j in range(1,m+1):
    time[j][0] = time[j-1][0] + b[j-1]
ans = 0
for i in range(1,n+1):
    for j in range(1,m+1):
        time[j][i] = time[j-1][i-1] + a[i-1] + b[j-1]
        if time[j][i] <= k and i+j >= ans:
            ans = i + j
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()))

cnt = 0

a_cnt = 0

b_cnt = 0

num = 0
while num < K:
    if N == a_cnt:
        if M == b_cnt:
            break
        else:
            num += b[b_cnt]
            b_cnt += 1
    elif M == b_cnt:
        if N == a_cnt:
            break
        else:
            num += a[a_cnt]    
            a_cnt += 1
    elif a[a_cnt] < b[b_cnt]:
        num += a[a_cnt]
        a_cnt += 1
    else:
        num += b[b_cnt]
        b_cnt += 1
    cnt += 1

if K < num:
    print(cnt-1)
else:
    print(cnt)

Submission status: Wrong Answer

Solution code:
import itertools as it
def main():
    n,m,k=map(int,input().split())
    a = list(it.accumulate(map(int, input().split())))
    b = list(it.accumulate(map(int, input().split())))
    ans = []
    for A in range(n-1,-1,-1):
        print("A", A)
        aa = a[A]
        Kaa = k-aa
        for B in range(m-1,-1,-1):
            print("B", B)
            if b[B] <= Kaa:
                ans.append(A+B+2)
                break
    print(max(ans) if len(ans) > 0 else 0)
    
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()]
b = [int(i) for i in input().split()]
time = 0
book_a = 0
book_b = 0

for i in range(len(a)):
    if time > k:
        break
    for j in range(len(b)):
        if time > k:
            break
        elif a[i] < b[j]:
            time = time + a[i]
            book_a = book_a + 1
            break
        else:
            time = time + b[j]
            book_b = book_b + 1

bb = b[book_b:]
if time < k:
    for i in bb:
        if time > k:
            break
        else:
            time = time + i
            book_b = book_b + 1

if book_a + book_b == len(a) + len(b):
    print(book_a + book_b)
else:
    print(book_a + book_b -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**9+1)
B.append(10**9+1)
ans=0
time=0
a=0
b=0
while K>time:
    if time+min(A[a],B[b])>K:
        break
    ans+=1
    time+=min(A[a],B[b])
    if A[a]>B[b]:
        b+=1
    else:
        a+=1
    if ans==N+M:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,m,k = readInts()
A = readInts()
B = readInts()
dA = deque(A)
dB = deque(B)

ans = []
if sum(A) + sum(B) <= k:
    print(n+m)
    exit()
else:
    # pre
    now = 0
    while True:
        if len(dA) == 0 and len(dB) == 0:
            break
        if len(dA) != 0 and len(dB) != 0:
            a =  dA.popleft()
            b =  dB.popleft()
            if a < b:
                now += a
                if now > k:
                    break
                ans.append(now)
                dB.appendleft(b)
            else:
                now += b
                if now > k:
                    break
                ans.append(now)
                dA.appendleft(a)
        elif len(dA) != 0 and len(dB) == 0:
            a = dA.popleft()
            now += a
            if now > k:
                break
            ans.append(now)
        elif len(dB) != 0 and len(dA) == 0:
            b = dB.popleft()
            now += b
            if now > k:
                break
            ans.append(now)
#print(ans)
import bisect
print(bisect.bisect_left(ans,k+1))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
m, n, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.extend(B)
del B
AB = sorted(A)
s=0
l=0
for i in AB:
    if s+i <= k:
        s+=i
        l+=1
    else:
        break
print("{}".format(l))

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

while time <= k:
    if i == len(a) and j == len(b):
        time += k
    elif i == len(a):
        time += b[j]
        if time >= k:
            break
        j += 1
        count += 1
    elif j == len(b):
        time += a[i]
        if time >= k:
            break
        i += 1
        count += 1
    elif a[i] <= b[j]:
        time += a[i]
        if time >= k:
            break
        i += 1
        count += 1
    elif a[i] > b[j]:
        time += b[j]
        if time >= k:
            break
        j += 1
        count += 1
"""
    elif a[i] == b[j]:
        if a[i+1] > b[j+1]:
            time += b[j]
            if time > k:
                break
            j += 1
            count += 1
        elif a[i+1] < b[j+1]:
            time += a[i]
            if time > k:
                break
            i += 1
            count += 1
"""
    

print(count)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
mx=n
mn=m
mxl=a
mnl=b
if m>n:
    mx=m
    mn=n
    mxl=b
    mnl=a
if k<a[0] and k<b[0]:
    print(0)
else:
    sm=0
    counts=[]
    i=0
    while sm<=k and i<n:
        sm+=a[i]
        i+=1
    counts.append(i)
    sm=0
    i=0
    while sm<=k and i<m:
        sm+=b[i]
        i+=1
    counts.append(i)
    sm=0
    i=0
    for j in range(mx):
        if sm<=k:
            sm+=mxl[j]
            i+=1
        if sm<=k and j<mn:
            sm+=mnl[j]
            i+=1
    counts.append(i)
    sm=0
    i=0
    for j in range(mx):
        if sm<=k and j<mn:
            sm+=mnl[j]
            i+=1
        if sm<=k:
            sm+=mxl[j]
            i+=1
          
    counts.append(i)
    print(max(counts))

Submission status: Wrong Answer

Solution code:
from decimal import *

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

a = list(map(int,input().split()))[::-1]
b = list(map(int,input().split()))[::-1]


#print(a)
#print(b)
ans = 0
while 1:
    #print(k, a,b)
    if b == [] and a == []:
        break
    elif b == [] and a != []:
        if a[-1] <= k:
            k -= a.pop()
            ans += 1
        else:
            break
    elif a == [] and b != []:
        if b[-1] <= k:
            k -= b.pop()
            ans += 1
        else:
            break
    else:
        k_a = k
        ans_a=0
        k_b = k
        ans_b=0
        for i in range(len(a)):
            if k_a < a[-1-i]:
                break
            k_a -= a[-i-1]
            ans_a += 1
        for i in range(len(b)):
            if k_b < b[-i-1]:
                break
            k_b -= b[-i-1]
            ans_b += 1
        if ans_a > ans_b:
            if k > a[-1]:
                k -= a.pop()
                ans+=1
            else:
                break
        else:
            if k > b[-1]:
                k -= b.pop()
                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()))
SA=[]
SB=[]
goukeiA=0
goukeiB=0
for i in range(N):
    goukeiA+=A[i]
    SA.append(goukeiA)
for i in range(M):
    goukeiB+=B[i]
    SB.append(goukeiB)

#def binary_search()
Mcount=0
for i in range(N):
    count=0
    nokori=K-SA[i]
    if nokori >=0 and nokori >=SB[M-1]:
        count+=i+1+M
    elif nokori >=0:
        count+=i+1
        tmp=nokori
        left=0
        right=M-1
        #flag=False
        while left<=right:
            #print("mohu")
            mid=(left+right)//2
            if SB[mid]<=nokori and SB[mid+1]>nokori:
                count+=mid+1
                #print("es",count,mid)
                break
            elif SB[mid]>nokori:
                #print(nokori,mid)
                right=mid-1
            elif SB[mid]<nokori:
                #print(nokori,mid)
                left=mid+1
            else:
                print("イレギュラーな例につかまりました")
                exit()
    if Mcount<count:
        #print("kita",count)
        Mcount=count
    
print(Mcount)

Submission status: Wrong Answer

Solution code:
para_list = list(map(int,input().split(' ')))
a_list = list(map(int,input().split(' ')))
b_list = list(map(int,input().split(' ')))

a_sum_list = []
b_sum_list = []

for i in range(para_list[0]):
    a_sum_list.append(sum(a_list[:i+1]))
    if(a_sum_list[-1]>para_list[2]):
        del a_sum_list[-1]
        break

for i in range(para_list[1]):
    b_sum_list.append(sum(b_list[:i+1]))
    if(b_sum_list[-1]>para_list[2]):
        del b_sum_list[-1]
        break


if(len(a_sum_list)==0 and len(b_sum_list)==0):
    print(0)
elif(len(a_sum_list)==0):
    print(len(b_sum_list))
elif(len(b_sum_list)==0):
    print(len(a_sum_list))
elif(a_sum_list[-1]+b_sum_list[-1]<=para_list[2]):
    print(para_list[0]+para_list[1])
else:
    ans = 1
    for i in range(len(a_sum_list)):
        for j in range(len(b_sum_list)):
            if(a_sum_list[i]+b_sum_list[j]<=para_list[2]):
                if(i+j+2>ans):
                    ans = i+j+2
    print(ans)

Submission status: Wrong Answer

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

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

ans = 0
time = 0

if sum(a) + sum(b) < k:
    print(len(a)+len(b))
else:
    while True:

        if not a and not b:
            break
        elif a and not b:
            mt = a[0]
            a.pop(0)
        elif not a and b:
            mt = b[0]
            b.pop(0)
        else:
            mt = min(a[0], b[0])
            if mt == a[0]:
                a.pop(0)
            if mt == b[0]:
                b.pop(0)
        
        time += mt
        if time > k:
            break

        ans += 1
        
    print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
n, m, k = map(int, input().split())
aList = list(map(int, input().split()))
bList = list(map(int, input().split()))

cList = [0]
dList = [0]
for a in aList:
    t = a + cList[-1]
    if t <= k:
        cList.append(a + cList[-1])
    else:
        break
for b in bList:
    t = b + dList[-1]
    if t <= k:
        dList.append(b + dList[-1])
    else:
        break
cList.pop(0)
dList.pop(0)
n = len(cList)
m = len(dList)

if len(cList) == 0:
    print(bisect.bisect_right(dList, k))
else:
    a = 0
    for i in range(0, n+1):
        lim = k - cList[n-1-i]
        a = max(a, n - i + bisect.bisect_right(dList, lim))
    print(a)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split(' '))
list_a = list(map(int, input().split(' ')))
list_b = list(map(int, input().split(' ')))

a_sum=[list_a[0]]
for i in range(1, n):
  sum=list_a[i]+a_sum[i-1]
  a_sum.append(sum)
  
b_sum=[list_b[0]]
for i in range(1, m):
  sum=list_b[i]+b_sum[i-1]
  b_sum.append(sum)
  
ans=[]
if (a_sum[0]>k) & (b_sum[0]>k):
  print(0)
else:
  if a_sum[0]<=k or b_sum[0]<=k:
    ans.append(1)
  for i in range(n):
    for j in range(m):
      if a_sum[i]+b_sum[j] <= k:
        key=i+j+2
        if key not in ans:
          ans.append(key)
  print(max(ans))

Submission status: Wrong Answer

Solution code:
N , M , K = map(float,input().split())
A = list(map(float,input().split()))
B = list(map(float,input().split()))
A.append(float(10**9+1))
B.append(float(10**9+1))
run_time = float(K)
count_A = int(0)
count_B = int(0)
#print(N, M ,K)
while(run_time > 0 or count_A + count_B >= N + M):
#	print(A[count_A] <= B[count_B] , run_time >= A[count_A] , count_A < N , "|" ,A[count_A] > B[count_B] , run_time >= B[count_B] , count_B < M)
	if(A[count_A] <= B[count_B] and run_time >= A[count_A] and count_A < N):
#		print(count_A, N)
#		print(N)
		run_time -= A[count_A]
		count_A += 1
	elif(A[count_A] > B[count_B] and run_time >= B[count_B] and count_B < M):
#		print(count_B , M)
		run_time -= B[count_B]
		count_B += 1
	else:
		break
print(count_A + count_B)

Submission status: Wrong Answer

Solution code:
from collections import deque

n, m, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
time = 0
ans = 0
aaa = deque(a)
bbb = deque(b)
while (time < k) & ((len(aaa) > 0)  |  (len(bbb) > 0)):
    if ((len(aaa) > 0)  &  (len(bbb) > 0)):
        i = 0
        while (i < min(len(aaa), len(bbb))):
            if aaa[i] < bbb[i]:
                time += aaa.popleft()
                ans += 1
                break
            elif aaa[i] > bbb[i]:
                time += bbb.popleft()
                ans += 1
                break
            elif i == min(len(aaa), len(bbb)) - 1:
                time += aaa.popleft()
                ans += 1
                break
            i += 1
    elif aaa:
        time += aaa.popleft()
        ans += 1
    elif bbb:
        time += bbb.popleft()
        ans += 1
if time <= k:
    print(ans)
else:
    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()))

a.sort()
b.sort()

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

Submission status: Wrong Answer

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

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

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


c = []

for i in range(m + n):
    if len(a) == 0:
        c.append(b[0])
        del b[0]
    elif len(b) == 0:
        c.append(a[0])
        del a[0]
    elif a[0] > b[0]:
        c.append(b[0])
        del b[0]
    else:
        c.append(a[0])
        del a[0]



ans = 0
d = 0
for i in range(m + n):
    d += c[i]
    if d > k:
        break
    else:
        ans += 1

print(ans)