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:
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
    sys.setrecursionlimit(10 ** 7)

    n, m, k = map(int, readline().split())
    a = list(map(int, readline().split())) + [float('inf')]
    b = list(map(int, readline().split())) + [float('inf')]
    aidx = 0
    bidx = 0
    for i in range(n + m):
        if a[aidx] > b[bidx]:
            k -= b[bidx]
            bidx += 1
        else:
            k -= a[aidx]
            aidx += 1
        if k < 0:
            print(i)
            break
    else:
        print(n + m)


if __name__ == '__main__':
    main()

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

A = deque(A[::-1])
B = deque(B[::-1])

count = 0

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

print(count)

Submission status: Wrong Answer

Solution code:
def _main(N, M, K, A, B):
    sum_k = 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:
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cnt=0
time=0
book=[A[0], B[0]]
while time+min(book)<=k:
    cnt+=1
    if min(book)==A[0]:
        time+=A[0]
        del A[0]
    else:
        time+=B[0]
        del B[0]
    book=[]
    if len(A)!=0:
        book.append(A[0])
    else:
        book.append(10**9+1)
        A.append(10**9+1)
    if len(B)!=0:
        book.append(B[0])
    else:
        book.append(10**9+1)
        B.append(10**9+1)
print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect
import numpy
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = numpy.cumsum(A)
b = numpy.cumsum(B)
ans = 0
for i in range(n):
    if a[i] <= k:
        c = bisect.bisect(b, k-a[i])
        ans = max(ans, i+c+1)

print(ans)

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
        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().strip().split())
A = list(map(int, input().strip().split()))[::-1]
B = list(map(int, input().strip().split()))[::-1]
time=0
ans=0
while A or B:
    if not B or A and A[-1]<B[-1]:
        time+=A.pop()
    else:
        time+=B.pop()
    if time>=k:
        break
    ans+=1

print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x,y,c,h=0,0,0,0
while(c<k):
  if(x>=n):
    while(y<m and c+b[y]<=k):
      h+=1
      c+=b[y]
      y+=1
    break           
  elif(y>=m):
    while(x<n and c+a[x]<=k):
      h+=1
      c+=a[x]
      x+=1
    break   
  else:
    if(a[x]<b[y]):
      if(c+a[x]>k):
        break
      else:
        c+=a[x]
        x+=1
        h+=1
    else:
      if(c+b[y]>k):
        break
      else:
        c+=b[y]
        y+=1
        h+=1
print(h)

Submission status: Wrong Answer

Solution code:
from collections import deque


def main():
    n, m, k = [int(x) for x in input().split()]
    array_a = deque(int(x) for x in input().split())
    array_b = deque(int(x) for x in input().split())
    count = 0
    inf = 1000000001
    book_a, book_b = -1, -1
    while True:
        if book_a == -1:
            try:
                book_a = array_a.popleft()
            except IndexError:
                book_a = inf
        if book_b == -1:
            try:
                book_b = array_b.popleft()
            except IndexError:
                book_b = inf

        if book_a <= book_b:
            to_read = book_a
            book_a = -1
        else:
            to_read = book_b
            book_b = -1

        if k >= to_read:
            k -= to_read
            count += 1
        else:
            break
    print(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
mod=10**9+7
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
from itertools import combinations
import bisect
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a,b,c=mi()
l=deque(list(mi()))
m=deque(list(mi()))
co=0
ans=0
while l and m:
  p=l.popleft()
  q=m.popleft()
  if p>=q:
    co+=q
    l.appendleft(p)
  else:
    co+=p
    m.appendleft(q)
  if co<=c:
    ans+=1
  else:
    print(ans)
    sys.exit()
if l:
  while l:
    e=l.popleft()
    co+=e
    if co<=c:
      ans+=1
    else:
      print(ans)
      sys.exit()
else:
  while m:
    f=m.popleft()
    co+=f
    if co<=c:
      ans+=1
    else:
      print(ans)
      sys.exit()
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()))

pointer_a = 0
pointer_b = 0
count = 0

while(True):
    if pointer_a == len(A):
        if pointer_b == len(B):
            break
        else:
            min_time = B[pointer_b]
            pointer_b += 1
    elif pointer_b == len(B):
        min_time = A[pointer_a]
        pointer_a += 1
    elif A[pointer_a] < B[pointer_b]:
        min_time = A[pointer_a]
        pointer_a += 1
    else:
        min_time = B[pointer_b]
        pointer_b += 1
    if (min_time <= K):
        K -= min_time
        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()))

ans = 0

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

    if (b == []):
        t = float("inf")
    else:
        t = b[0]

    if (min(s, t) > k):
        break
    elif (s > t):
        k -= b.pop(0)
        ans += 1
    elif (t > s):
        k -= a.pop(0)
        ans += 1

print(ans)

Submission status: Wrong Answer

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

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

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

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

if __name__=='__main__':
    main()

Submission status: Wrong Answer

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

S = 0
a_idx = 0
for a in A:
    if S + a > K:
        break
    S += a
    a_idx += 1

b_idx = 0
for b in B:
    if S + b > K:
        break
    S += b
    b_idx += 1

ans = a_idx + b_idx
while a_idx > 0:
    a_idx -= 1
    while b_idx < M and S + B[b_idx] <= K:
        S += B[b_idx]
        b_idx += 1
    ans = max(ans, a_idx + b_idx)
print(ans)

Submission status: Wrong Answer

Solution code:
#!python3.8
# -*- coding: utf-8 -*-
# abc172/abc172_c
import sys
from collections import deque

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, M, K = i2nn()
    A = deque(i2nn())
    B = deque(i2nn())
    t = 0
    n = 0
    while True:
        if A and B:
            u = A.popleft() if A and (A[0] < B[0]) else B.popleft()
            if t + u >= K:
                break
            t += u
            n += 1
        elif A:
            u = A.popleft()
            if t + u >= K:
                break
            t += u
            n += 1
        elif B:
            u = B.popleft()
            if t + u >= K:
                break
            t += u
            n += 1
        else:
            break
        
    print(n)
    return

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

# 経過時間
t = 0
# 読んだ本
book_count = 0

while t <= K:
    if len(A) == 0 and len(B) == 0:
        break
    elif len(A) == 0:
        t += B.pop(0)
        if t <= K:
            book_count += 1
    elif len(B) == 0:
        t += A.pop(0)
        if t <= K:
            book_count += 1
    else:
        if A[0] < B[0]:
            t += A.pop(0)
            if t <= K:
                book_count += 1
        else:
            t += B.pop(0)
            if t <= K:
                book_count += 1

print(book_count)

Submission status: Wrong Answer

Solution code:
l = input()
l = l.split()
n,m,k = l[0], l[1], int(l[2])
a = input().split()
b = input().split()

total = a+b
ans = 0

for i in range(int(n)+int(m)):
    total[i] = int(total[i])

total = sorted(total)

for i in total:
    if k - i >= 0:
        ans += 1
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
n,m,k=map(int,input().split())
A=deque(list(map(int,input().split()))+[10**9+1])
B=deque(list(map(int,input().split()))+[10**9+1])

point=0
while k>0:
    num=0
    if A[0]==10**9+1 and B[0]==10**9+1:break

    if A[0]>B[0]:num=B.popleft()
    else:num=A.popleft()

    if k-num>=0:
        point +=1
        k -=num
    else:break


print(point)

Submission status: Wrong Answer

Solution code:
import heapq

def solve(A, B, K):

    N = len(A)
    M = len(B)

    min_heap = []

    A_MARKER, B_MARKER = 0, 1
    heapq.heappush(min_heap, (A[0], A_MARKER, 0))
    heapq.heappush(min_heap, (B[0], B_MARKER, 0))

    k = 0
    count = 0
    while k <= K and min_heap:

        mins, marker, idx = heapq.heappop(min_heap)
        if k + mins > K:
            return count

        if marker == A_MARKER and idx + 1 < N:
            heapq.heappush(min_heap, (A[idx + 1], A_MARKER, idx + 1))
        elif marker == B_MARKER and idx + 1 < M:
            heapq.heappush(min_heap, (B[idx + 1], B_MARKER, idx + 1))

        k += mins
        count += 1

    return count

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

print(solve(A, B, K))

Submission status: Wrong Answer

Solution code:
from collections import deque

N,M,K=map(int,input().split())
A_list=list(map(int,input().split()))
B_list=list(map(int,input().split()))
A=deque(A_list)
B=deque(B_list)
time = 0
cnt = 0
while time <= K:
  if len(A) == 0 and len(B) == 0:
    break
  elif len(A) == 0:
    tmp = B.popleft()
  elif len(B) == 0:
    tmp = A.popleft()
  elif A[0]<B[0]:
    tmp = A.popleft()
  else:
    tmp = B.popleft()
  time += tmp
  if time > K:
    break
  cnt += 1
#  print(time,A,B)
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

an = deque(an)
bn = deque(bn)
ans = -1
while k >= 0:
  if len(bn) == 0 and len(an) == 0:
    print(ans + 1)
    exit()
  if len(an) == 0:
    x = bn.popleft()
    k -= x
  elif len(bn) == 0:
    x = an.popleft()
    k -= x
  elif an[0] <= bn[0]:
    x = an.popleft()
    k -= x
  else:
    x = bn.popleft()
    k -= x

  ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = [int(s) for s in input().split(" ")]
alist = [int(s) for s in input().split(" ")]
blist = [int(s) for s in input().split(" ")]

aind = 0
bind = 0
cur_time = 0
while True:
  if aind < len(alist) and bind < len(blist) and alist[aind] > blist[bind]:
    cur_time += blist[bind]
    if cur_time > k:
      break
    bind += 1
  elif aind < len(alist) and bind < len(blist) and alist[aind] <= blist[bind]:
    cur_time += alist[aind]
    if cur_time > k:
      break
    aind += 1
  elif aind >= len(alist) and bind < len(blist):
    cur_time += blist[bind]
    if cur_time > k:
      break
    bind += 1
  elif aind < len(alist) and bind >= len(blist):
    cur_time += alist[aind]
    if cur_time > k:
      break
    aind += 1
  else:
    break

print(aind + bind)

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()))
A_Read = 0
B_Read = 0
A_Finish = 0
B_Finish = 0
ans = 0
while K >= 0:
    if A_Finish == 1 and B_Finish == 1:
        break
    elif A_Finish == 1:
        K -= B_list[B_Read]
        B_Read += 1
    elif B_Finish == 1:
        K -= A_list[A_Read]
        A_Read += 1
    else:
        if A_list[A_Read] <= B_list[B_Read]:
            K -= A_list[A_Read]
            A_Read += 1
            if A_Read == N:
                A_Finish = 1
        else:
            K -= B_list[B_Read]
            B_Read += 1
            if B_Read == M:
                B_Finish = 1
    if K < 0:
        break
    elif K == 0:
        ans += 1
        break
    # print(K)
    ans += 1
print(ans)

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()))
sa = [0] * (n+1)
for i in range(n):
    sa[i+1] = sa[i] + a[i]
sb = [0] * (m+1)
for i in range(m):
    sb[i+1] = sb[i] + b[i]

ans = 0
for i in range(1,n+1):
    bi = min(m, bisect.bisect_right(sb, max(0, k-sa[i]+1))-1)
    if sa[i] + sb[bi] <= k:
        ans = max(ans, i + bi)
print(ans)

Submission status: Wrong Answer

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

i=0
j=0
cnt=0
while(i<n and j<m and k>=0):
    if(a[i]<b[j]):
        if(k-a[i]>=0):
            k=k-a[i]
            cnt+=1
            i+=1
        else:
            break
    else:
        if(k-b[j]>=0):
            k=k-b[j]
            cnt+=1
            j+=1
        else:
            break
while(i<n and k>=0):
    if(k-a[i]>=0):
        k=k-a[i]
        cnt+=1
        i+=1
    else:
        break
while(j<m and k>=0):
    if(k-b[j]>=0):
        k=k-b[j]
        cnt+=1
        j+=1
    else:
        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()))
qa = deque(A)
qb = deque(B)
ans = 0
total = 0
while total <= k:
    if n > 0 and m > 0:
        if qa[0] >= qb[0]:
            p = qb.popleft()
            total += p
            m -= 1
        else:
            p = qa.popleft()
            total += p
            n -= 1
        ans += 1
    elif n >0:
        p = qa.popleft()
        total += p
        n -= 1
        ans += 1
    elif m > 0:
        p = qb.popleft()
        total += p
        m -= 1
        ans += 1
    else:
        print(ans)
        exit()
print(ans-1)

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

cnt=0

while k>0:
  if len(A)==0:
    A.append(9999999999)
  if len(B)==0:
    B.append(9999999999)
    
  if A[0]<=B[0] and A[0]<=k:
    k=k-A.popleft()
    cnt+=1
  elif A[0]>=B[0] and B[0]<=k:
    k=k-B.popleft()
    cnt+=1
  else:
    break

print(cnt)

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())))
t = 0
x, y = a.popleft(), b.popleft()
if sum(a) + sum(b) < k:
    print(n + m)
    exit()
while k > 0:
    if x > y:
        k -= y
        if b:
            y = b.popleft()
        else:
            y = float("inf")
    else:
        k -= x
        if a:
            x = a.popleft()
        else:
            x = float("inf")
    t += 1
print(t - 1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
# stdin = open("sample.txt")

MOD = 1000000007
INF = float('inf')
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

def keta(kazu): # 入力されたintを桁ごとに分解，リストで出力
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers): # 最小公倍数
    return reduce(math.gcd, numbers)

def combination(m,n): # mCn
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def pow_k(x,n):  # (x**n)の計算の高速化
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x

def main():
    n,m,k= [int(x) for x in stdin.readline().rstrip().split()]
    a = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
    b = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
    a_now = 0
    b_now = 0
    ans = 0
    
    while k > 0:
        if a_now >= n:
            a_check = INF
        else:
            a_check = a[a_now]
        if b_now >= m:
            b_check = INF
        else:
            b_check = b[b_now]
        if a_now == INF and b_now == INF:
            break
        
        if a_check <= b_check:
            k -= a_check
            a_now += 1
            # print("a")
        elif a_check > b_check:
            k -= b_check
            b_now += 1
            # print("b")
        if k >= 0:
            ans += 1
        else:
            break
    print(ans)
            
main()

Submission status: Wrong Answer

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

out, t, i, j = 0 , 0, 0, 0
while t <= k:
    a_n = a_list[i] if i < len(a_list) else 10 ** 10
    b_n = b_list[j] if j < len(b_list) else 10 ** 10
    if a_n <= b_n:
        t += a_n
        i += 1
        out += 1
    else:
        t += b_n
        j += 1
        out += 1

print(out - 1)

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

n,m = 0,0
ans = 0
pre = 0
cnt =0
while ans<K:
    if n>=N or m>=M:
        break
    if A[n] < B[m]:
        ans += A[n]
        pre = A[n]
        n+=1
        cnt +=1
    else:
        ans += B[m]
        pre = B[m]
        m+=1
        cnt += 1

if n==N and m<M:
    while ans<K:
        if m>=M:
            break
        ans += B[m]
        pre = B[m]
        m+=1
        cnt += 1
elif n<N and m==M:
    while ans<K:
        if n>=N:
            break
        ans += A[n]
        pre = A[n]
        n+=1
        cnt += 1
if ans>K:
    ans -= pre
    cnt -=1

print(cnt)

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()]
ai = 0
bi = 0
ans = 0
while ai<n or bi<m:
    if k<=0:
        break
    if ai<n and bi==m:
        k -= a[ai]
        ai+=1
    elif bi<m and ai==n:
        k -= b[bi]
        bi+=1
    else:
        k -= min(a[ai],b[bi])
        if a[ai]<=b[bi]:
            ai+=1
        else:
            bi+=1
    ans += 1
if k<0:
    print(ans-1)
else:
    print(ans)

Submission status: Wrong Answer

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

cnt = 0
ans = -1
while cnt <= k:
    ans += 1
    if len(a) == 0 and len(b) == 0:
        break
    elif len(a) == 0:
        cnt += b.pop(0)
    elif len(b) == 0:
        cnt += a.pop(0)
    else:
        if a[0] >= b[0]:
            cnt += b.pop(0)
        else:
            cnt += a.pop(0)
            
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ia, ib = 0, 0
ca, cb = 0, 0
t = 0
cnt = 0
INF = 987654321

while True:
    if a:
        ca = a[0]
    else:
        ca = INF
    if b:
        cb = b[0]
    else:
        cb = INF

    if ca >= cb:
        t += cb
        b.pop()
    elif ca < cb:
        t += ca
        a.pop()
    
    if t > k:
        break
    
    cnt += 1

    if cnt == n+m:
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
    M , N, K = map(int, input().split())
    A_list = [A for A in input().split()]
    B_list = [B for B in input().split()]
    A_list = list(map(int, A_list))
    B_list = list(map(int, B_list))
    #print(A_list)
    #print(B_list)
    count = 0
    time = 0
    for i in range(N + M) :
        #print(A_list)
        #print(B_list)
        if A_list == [] :
            A_list.append(10000000000)
        elif B_list == []:
            B_list.append(10000000000)
        if A_list[0] < K and A_list[0] < B_list[0] and A_list != [] :
            time = time + A_list[0]
            A_list.pop(0)
            if time <= K :
                count += 1
            else :
                break
        elif B_list[0] < K and B_list[0] < A_list[0] and B_list != [] :
            time = time + B_list[0]
            B_list.pop(0)
            if time <= K :
                count += 1
            else :
                break
    print(count)


if __name__ == '__main__':
    main()

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())))
read_time = 0
cnt = 0
if sum(a) + sum(b) <= k:
    print(len(a) + len(b))
else:
    while a or b:
        if not a:
            read_time += b.popleft()
            if read_time >= k:
                break
            cnt += 1
        elif not b:
            read_time += a.popleft()
            if read_time >= k:
                break
            cnt += 1
        else:
            if a[0] <= b[0]:
                read_time += a.popleft()
                if read_time >= k:
                    break
                cnt += 1
            elif a[0] > b[0]:
                read_time += b.popleft()
                if read_time >= k:
                    break
                cnt += 1
    print(cnt)

Submission status: Wrong Answer

Solution code:
(n,m,k)= list(map(int,input().split()))
lis = list(map(int,input().split()))
lisn = list(map(int,input().split()))
lis.reverse()
lisn.reverse()
v = 0
ct = 0
while v <=k:
	if lis and lisn:
		a = lis[-1]
		b = lisn[-1]
		if a > b:
			c = lisn.pop()
			if v + c> k:
				break
			else:
				v+=c 
				ct+= 1
		else:
			c = lis.pop()
			if v + c> k:
				break
			else:
				v+=c 
				ct+= 1
	elif lis and not lisn:
		c = lis.pop()
		if v + c> k:
			break
		else:
			v+=c 
			ct+= 1
	elif not lis and lisn:
		c= lisn.pop()
		if v + c> k:
			break
		else:
			v+=c 
			ct+= 1
	else:
		break 
print(ct)

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
j = 0
k = 0
book = 0
for i in range(N+M):
    if time > K:
        book -= 1
        break
    if j < N and k < M:
        if A[j] < B[k] :
            time += A[j]
            book += 1
            j += 1
        elif A[j] > B[k]:
            time += B[k]
            book += 1
            k += 1
    else:
        if j >= N and k < M:
            time += B[k]
            book +=1
            k += 1
        elif j < N and k >= M:
            time += A[j]
            book += 1
            j += 1
        else:
            break
print(book)

Submission status: Wrong Answer

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

ni = 0
mi = 0
ans = 0


ab = []

while k >= ans:

  if n == ni and m == mi:
    break
  elif n == ni:
    ans += b[mi]
    mi += 1
  elif m == mi:
    ans += a[ni]
    ni += 1
  elif a[ni] <= b[mi]:
    ans += a[ni]
    ni += 1
  else:
    ans += b[mi]
    mi += 1

cal = ni + mi
if n != ni or m != mi:
  cal -= 1
print(cal)

Submission status: Wrong Answer

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

n,m,k = lr()
a = lr()
b = lr()
a.reverse()
b.reverse()
a1 = [0]
b1 = [0]
for num in a:
    a1.append(a1[-1]+num)
for num in b:
    b1.append(b1[-1]+num)
def sumAreaA(l,r):
    return a1[r]-a1[l]
def sumAreaB(l,r):
    return b1[r]-b1[l]

ans = 0
dame = bisect.bisect_left(a1,k)
if dame < n+1:
    if a1[dame] == k:
        dame+=1
for i in range(dame):
    pre = i
    pretime = sumAreaA(0,i)
    time = k-pretime
    ind = bisect.bisect_left(b1,time)
    if ind == 0:
        ans = max(ans,pre)
    elif ind < m+1:
        if b1[ind] == k:
            ind+=1
        ans = max(ans,pre+ind)
    else:
        ans = max(ans, pre+m)
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
t = 0
if k<a[0] and k<b[0]:
  print(0)
else:
  while t < k:
    ans += 1
    if a!=[] and b!=[]:
      if a[0] > b[0]:
        t += a[0]
        a.pop()
      elif a[0] < b[0]:
        t += b[0]
        b.pop()
    elif a==[] and b!=[]:
      t += b[0]
      b.pop()
    elif b==[] and a!=[]:
      t += a[0]
      a.pop()
    else:
      print(n+m)
      exit()
  
  print(ans)