Problem:


Score : 300 points

Problem Statement

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

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

Consider the following action:

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

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

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

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

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

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

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

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

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

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

Sample Output 3

0

Watch out for integer overflows.



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


Sample output:
3

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a_cum = np.cumsum(a)
b_cum = np.cumsum(b)

if a_cum[-1] + b_cum[-1] <= k:
  print(n+m)
  exit()
  
def find(array, x):
  for i in range(len(array)):
    if array[i] > x:
      return i-1
  else:
    return len(array)-1

idx = find(a_cum, k)
ans = idx+1

for i in range(0, idx+1):
  tmp = k - a_cum[idx-i]
  tmpidx = find(b_cum, tmp)
  ans = max(idx+1 - i + tmpidx+1, ans)
    
print(ans)

Submission status: Wrong Answer

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

# もしすべてaから選んだ場合
time = k
aOnly = 0
for i in range(len(a)):
    time -= a[i]
    if time < 0:
        time += a[i]
        i -= 1
        break
    aOnly += 1
a_idx = i
b_idx = -1

for i in range(len(b)):
    time -= b[i]
    if time < 0:
        time += b[i]
        i -= 1
        break
    aOnly += 1
b_idx = i
ans = aOnly

ans_kari = ans
for i in range(a_idx, -1, -1):
    time += a[i]
    ans_kari -= 1
    for j in range(b_idx+1, len(b)):
        time -= b[j]
        if time < 0:
            time += b[j]
            b_idx = i-1
            break
        ans_kari += 1
    ans = max(ans, ans_kari)
    
print(ans)

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()]
a_i = 0
b_i = 0
count = 0
while(K>=0):
    if a_i == N and b_i == M:
        break
    elif a_i == N:
        K -= B[b_i]
        b_i += 1
        count+=1
    elif b_i == M:
        K -= A[a_i]
        a_i += 1
        count+=1
    else:
        if A[a_i]<B[b_i]:
            K -= A[a_i]
            a_i += 1
        else:
            K -= B[b_i]
            b_i += 1
        count+=1
    if K<0:
        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()))

count_A = 0
count_B = 0
i = 0
j = 0
ans = 0
time = K

while 1:
    if count_A < N and count_B < M:
        if A[i] <= B[j]:
            ans += 1
            time -= A[i]
            i += 1
            count_A += 1
        else:
            ans += 1
            time -= B[j]
            j += 1
            count_B += 1
    elif count_A < N:
        ans += 1
        time -= A[i]
        i += 1
        count_A += 1
    elif count_B < M:
        ans += 1
        time -= B[j]
        j += 1
        count_B += 1
    else:
        break

    if time < 0:
        ans -= 1
        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()))
sum = 0
j = 0
l = 0
count = 0

for i in range(10 ** 9 * 10 ** 9):


    if A == [] and B == []:
        break

    if A == [] or B == []:
        if A == []:
            if B[0] + sum <= K:
                sum += B[0]
                B.pop(0)
                count += 1
                # j += 1
            else:
                break
        elif B == []:
            if A[0] + sum <= K:
                sum += A[0]
                A.pop(0)
                count += 1
                # j += 1
            else:
                break
    else:
        if A[0] > B[0]:
            if B[0] + sum <= K:
                sum += B[0]
                B.pop(0)
                count += 1
                # j += 1
            else:
                break
        else:
            if A[0] + sum <= K:
                sum += A[0]
                A.pop(0)
                count += 1
                # l += 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()))
A.append(K + 1)
B.append(K + 1)
ia, ib = 0, 0
time = 0
flag = True
while flag:
    flag = False
    if A[ia] < B[ib] and time + A[ia] <= K:
        time += A[ia]
        ia += 1
        flag = True
    if B[ib] <= A[ia] and time + B[ib] <= K:
        time += B[ib]
        ib += 1
        flag = True
print(ia + ib)

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 collections import deque
p=deque(a)
q=deque(b)

import sys
time=0
ans=0
while(1):
    if len(p)==0 and len(q)==0:
        print(ans)
        sys.exit()
    if len(p)>0 and len(q)>0:
        if p[0]>q[0]:
            time=time+q.popleft()
            if time>k:
                print(ans)
                sys.exit()
            else:
                ans=ans+1
        elif p[0]<q[0]:
            time=time+p.popleft()
            if time>k:
                print(ans)
                sys.exit()
            else:
                ans=ans+1
        elif p[0]==q[0] and len(p)==1:
            time=time+q.popleft()
            if time>k:
                print(ans)
                sys.exit()
            else:
                ans=ans+1
        elif p[0]==q[0] and len(q)==1:
            time=time+q.popleft()
            if time>k:
                print(ans)
                sys.exit()
            else:
                ans=ans+1
        else:
            if p[1]>=q[1]:
                la=q.popleft()
                if la==1000000000:
                    print(ans)
                    sys.exit()
                time=time+la
                if time>k:
                    print(ans)
                    sys.exit()
                else:
                    ans=ans+1
            else:
                la=p.popleft()
                if la==1000000000:
                    print(ans)
                    sys.exit()
                time=time+la
                if time>k:
                    print(ans)
                    sys.exit()
                else:
                    ans=ans+1
    elif len(p)==0:
        la=q.popleft()
        if la==1000000000:
            print(ans)
            sys.exit()
        time=time+la
        if time>k:
            print(ans)
            sys.exit()
        else:
            ans=ans+1
    elif len(q)==0:
        la=p.popleft()
        if la==1000000000:
            print(ans)
            sys.exit()
        time=time+la
        if time>k:
            print(ans)
            sys.exit()
        else:
            ans=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()))

max_val = pow(10, 9) + 10

time = 0
book_count = 0
a_idx, b_idx = 0, 0

while time <= K:
  # index out of range
  tmp_a = A[a_idx] if a_idx < N else max_val
  tmp_b = B[b_idx] if b_idx < M else max_val
  # すでに本がない場合も終了？
  if (a_idx >= N) and (b_idx >= M):
    break
  # 今回読んだら時間を超える場合、ここで終了
  if time + min(tmp_a, tmp_b) > K:
    break
  if tmp_a <= tmp_b:
    time += tmp_a
    a_idx += 1
  else:
    time += tmp_b
    b_idx += 1
  book_count += 1

print(book_count)

Submission status: Wrong Answer

Solution code:


def main3():
    n, m, k = map(int, input().split())
    aa = list(map(int, input().split()))
    bb = list(map(int, input().split()))
    time_sum = 0
    counter = 0
    ans = []

    if bb[0] >= aa[0]:
        if k < aa[0]:
            return counter
    if bb[0] <= aa[0]:
        if k < bb[0]:
            return counter

    if (sum(aa)+sum(bb)) <= k:
        return n+m

    for i in range(n+1):
        counter = i
        time_sum = sum(aa[:i])
        if time_sum > k:
            break
        elif time_sum == k:
            ans.append(counter)
        else:
            for j in range(1, m):
                time_sum += bb[j]
                if time_sum < k:
                    counter += 1
                elif time_sum == k:
                    counter += 1
                    ans.append(counter)
                else:
                    ans.append(counter)
                    break

    if len(ans) == 1:
        return ans[0]
    else:
        return max(ans)


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

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 
tmp = time
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]:
            if tmp+a[0] > k:
                break
            time += a[0]
            tmp = time
            ans += 1
            a.pop(0)
        else:
            if tmp+b[0] > k:
                break
            time += b[0]
            tmp = time
            ans += 1
            b.pop(0)

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

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

print(ans)

Submission status: Wrong Answer

Solution code:

N,M,K = map(int, input().split())
Alist = list(map(int, input().split()))
Blist = list(map(int, input().split()))

time = 0
count = 0

while(True):
  if (len(Alist) != 0) and (len(Blist) != 0):
    if Blist[0] <= Alist[0]:
      time += Blist.pop(0)
      if time > K:
        break
      count += 1  
    else:
      time += Alist.pop(0)
      if time > K:
        break
      count += 1
  
  elif (len(Alist) == 0) and (len(Blist) != 0):
    if time+Blist[0] > K:
      break
    else:
      time += Blist.pop(0)
      count += 1
  
  elif (len(Alist) != 0) and (len(Blist) == 0):
    if time+Alist[0] > K:
      break
    else:
      time += Alist.pop(0)
      count += 1
  
  else:
    break
    
print(count)

Submission status: Wrong Answer

Solution code:
# = int(input())
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]
count = 0
A.append(10**9+1)
B.append(10**9+1)
A.append(10**9+1)
B.append(10**9+1)

ilist = [0]
jlist = [0]
dcount = 0

i = 0
j = 0
while K >= 0:
    if A[i] == B[j]:
        if A[i+1] < B[j+1]:
            count += 1
            K -= A[i]
            if K >= 0:
                i += 1
                ilist.append(1)
                jlist.append(0)
            else:
                check = 1
        else:
            count += 1
            K -= B[j]
            if K >= 0:
                j += 1
                ilist.append(0)
                jlist.append(1)
            else:
                check = 2
    elif A[i] < B[j]:
        count += 1
        K -= A[i]
        if K >= 0:
            i += 1
            ilist.append(1)
            jlist.append(0)
        else:
            check = 1
    else:
        count += 1
        K -= B[j]
        if K >= 0:
            j += 1
            ilist.append(0)
            jlist.append(1)
        else:
            check = 2

if check == 1:
    K += A[i]
else:
    K += B[j]

if ilist[-1] == 1:
    K += A[i-1]

    while K >= 0:
        if B[j] <= K:
            K -= B[j]
            j += 1
            dcount += 1
        else:
            break
if jlist[-1] == 1:
    K += B[j-1]
    while K >= 0:
        if A[i] <= K:
            K -= A[i]
            i += 1
            dcount += 1
        else:
            break

if dcount >= 2:
    print(dcount+count-2)
else:
    print(count-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()))
cnt=0
temp=0
Ai=0
Bi=0
for i in range(n+m):
  if Ai==n and Bi==m:
    break;
  elif Ai==n and Bi<m:
    if temp+B[Bi]<=k:
      temp+=B[Bi]
      cnt+=1
      Bi+=1
    else:
      break;
  elif Bi==m and Ai<n:
    if temp+A[Ai]<=k:
      temp+=A[Ai]
      cnt+=1
      Ai+=1
    else:
      break;
  elif Ai<n and Bi<m:
    if A[Ai]<B[Bi]:
      if temp+A[Ai]<=k:
        temp+=A[Ai]
        cnt+=1
        Ai+=1
      else:
        break;
    elif A[Ai]>=B[Bi]:
      if temp+B[Bi]<=k:
        temp+=B[Bi]
        cnt+=1
        Bi+=1
      else:
        break;

print(cnt)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
s = a + b
s.sort()
ans = 0
book = 0
for i in range(len(s)):
  if ans < k:
    if ans+s[i] <= k:
      ans += s[i]
      book += 1
    else:
      break

print(book)

Submission status: Wrong Answer

Solution code:
a=[]
b=[]
lst=[]
str = input()
str1 = input()
str2 = input()
lst = str.split(' ')
n,m,k = lst
n = int(n)
m = int(m)
k = int(k)

a = str1.split(' ')
b = str2.split(' ')
i=0
j=0
count = 0
c=0
flaga=0
flagb = 0
#print(a)
#print(k)
while c<=k  and count<len(a)+len(b) and ( flaga==0 or flagb==0):
  
  
  if i<len(a):
    
    c = c+int(a[i])
    if c<=k:
      #a.pop(i)
      i = i+1
      count = count+1
    else:
      c = c-int(a[i])
      flaga=1
  #print("c:",c)
  if j<len(b):
    c = c+int(b[j])
    if c<=k:
      #b.pop(j)
      j = j+1
      count = count+1
    else:
      c = c-int(b[j])
      flagb=1
    #print("c:",c)
print(count)

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()))
time = 0
count = 0
que_a = deque(a)
que_b = deque(b)
for i in range(n+m):
    if len(que_a)==0 or len(que_b)==0:
        if len(que_a)==0:
            time +=que_b.popleft()
            if time >k:
                print(count)
                exit()
            count+=1
        elif len(que_a)==0:
            time +=que_b.popleft()
            if time >k:
                print(count)
                exit()
            count+=1
    else:
        if que_a[0]>que_b[0]:
            time += que_b.popleft()
            if time > k:
                print(count)
                exit()
            count += 1
        else:
            time += que_a.popleft()
            if time > k:
                print(count)
                exit()
            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()))

time = 0
count = 0
i = 0
j = 0
for _ in range(n + m):
    if a[i] < b[j]:
        time += a[i]
        if i == len(a) -1:
            a.append(10 ** 9 + 1)
        i += 1
    elif a[i] > b[j]:
        time += b[j]
        if j == len(b) - 1:
            b.append(10**9+1)
        j +=1
    else:
        time += a[i]
        if i == len(a) - 1:
            a.append(10 ** 9 + 1)
            i += 1
        elif j == len(b) - 1:
            b.append(10**9+1)
            j += 1
        else:
            if a[i + 1] < b[j+1]:
                i += 1
            else:
                j += 1
    if time > k:
        break
    else:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().strip().split())
a=list(map(int,input().strip().split()))
b=list(map(int,input().strip().split()))
total=0
i=0
j=0
ans=0
while(i<n and j<m):
    if(a[i]==b[j] and (a[i]+b[j]+total)<=k):
        total+=(a[i]*2)
        ans+=2
        i+=1
        j+=1
    elif(a[i]==b[j] and (a[i]+total)<=k):
        total+=a[i]
        ans+=1
        p=i+1
        q=j+1
        flag=0
        while(p<n and q<m):
            if(a[p]<b[q]):
                i+=1
                flag=1
                break
            elif(b[q]<a[p]):
                j+=1
                flag=1
                break
            p+=1
            q+=1
        if(flag==0):
            i+=1
    elif(a[i]<b[j] and (a[i]+total)<=k):
        total+=a[i]
        ans+=1
        i+=1
    elif(b[j]<a[i] and (b[j]+total)<=k):
        total+=b[j]
        ans+=1
        j+=1
    else:
        break
while(i<n):
    if((a[i]+total)>k):
        break
    total+=a[i]
    ans+=1
    i+=1
while(j<m):
    if((b[j]+total)>k):
        break
    total+=b[j]
    ans+=1
    j+=1
print(ans)

Submission status: Wrong Answer

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

iter = list(x for x in itertools.chain.from_iterable(itertools.zip_longest(A,B)) if x)
cnt =  0
sum = 0
for i in iter:
    sum += i
    if sum >= K:
        break
    else:
        cnt +=1
print(iter)
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()))
MAX = 10 ** 9 + 7
A.append(MAX)
B.append(MAX)
a, b, time = 0, 0, 0
for i in range(0,len(A)+len(B)-1):
    if A[a] == B[b]:
        if A[a] == MAX:
            break
        if A[a+1] < B[b+1]:
            time += A[a]
            a += 1
        else:
            time += B[b]
            b += 1
    elif A[a] <= B[b]:
        time += A[a]
        a += 1
    else:
        time += B[b]
        b += 1
    if time > K:
        break
print(i)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint


def ceil(a, b): return (a + b - 1) // b


inf = float('inf')
mod = 10 ** 9 + 7


def pprint(*A):
    for a in A:     print(*a, sep='\n')


def INT_(n): return int(n) - 1


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


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [I() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')

def main():
    N, M, K = MI()
    A = LI()
    B = LI()
    total = 0
    a_index = 0
    b_index = 0
    is_finish_a = 0
    is_finish_b = 0
    lena = len(A)
    lenb = len(B)
    for i in range(N+M+1):
        # print("is_finish_a")
        # print(is_finish_a)
        # print(is_finish_b)
        # print(a_index)
        # print(b_index)
        # if lena + lenb - 2 == a_index + b_index:
        #     print(a_index+b_index)
        #     sys.exit()
        # print("i")
        # print(i)
        if is_finish_a == 1 and is_finish_b == 1:
            print(a_index+b_index)
            sys.exit()
        if is_finish_a == 0 and is_finish_b == 0 and total + A[a_index] > K and total + B[b_index] > K:
            print(a_index+b_index)
            sys.exit()
            break
        if is_finish_a == 1:
            if total + B[b_index] > K:
                print(a_index+b_index)
                sys.exit()
            else:
                total+=B[b_index]
                b_index+=1
                if b_index == lenb:
                    is_finish_b = 1
            continue
        if is_finish_b == 1:
            if total + A[a_index] > K:
                print(a_index+b_index)
                sys.exit()
            else:
                total+=A[a_index]
                a_index+=1
                if a_index == lena:
                    is_finish_a = 1
            continue

        if is_finish_a == 1 or is_finish_b == 1:
            continue

        if is_finish_a == 0 and is_finish_b == 0 and A[a_index] > B[b_index]:
            total+=B[b_index]
            b_index+=1
            # print("b_index")
            # print(b_index)
            if b_index == lenb:
                is_finish_b = 1
        elif is_finish_a == 0 and is_finish_b == 0:
            total+=A[a_index] 
            a_index+=1
            if a_index == lena:
                is_finish_a = 1
            # print("a_index")
            # print(a_index)


if __name__ == '__main__':
    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()))
maxa = 0
for i in range(N):
  maxa += A[i]
  if maxa > K:
    maxa -= A[i]
    i -= 1
    break

#Aだけ読み進めるとi+1冊読める
yomeruA = A[:i + 1][::-1]
time = K - maxa
for j in range(M):
  time -= B[j]
  if time < 0:
    j -= 1
    break

#残り時間でBを読み進めるとj+1冊読める
result = i + j + 2
tmpresult = result
time = time + B[j]
for a in yomeruA:
  # Aを１冊諦めたら？
  tmpresult -= 1
  time += a
  for b in B[j:]:
    if time < 0:
      break
    else:
      time -= b
      tmpresult += 1
      j += 1
  if tmpresult > result:
    result = tmpresult
print(result)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int,input().split())
a=list(map(int,input().split()))+list(map(int,input().split()))
a.sort()
c=0
for i in range(n+m):
  if(k-a[i]<0):
    break
  k-=a[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 = 0
ans = -1
ia = 0
ib = 0
while c <= K:
  if ia == N and ib == M:
    ans += 1
    break
  elif ia == N:
    c += B[ib]
    ib += 1
     
  elif ib == M:
    c += A[ia]
    ia += 1
    
  elif A[ia] <= B[ib]:
    c += A[ia]
    ia += 1
     
  else:
    c += B[ib]
    ib += 1
    
  ans += 1
print(ans)

Submission status: Wrong Answer

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

time = 0
cnt = 0
for i in range(N+K):
    if len(al) >= 1 and len(bl) >= 1:
        if al[0] >= bl[0]:
            time += bl[0]
            if time > K:
                print(cnt)
                exit()
            else:
                bl.popleft()
                cnt += 1
        else:
            time += al[0]
            if time > K:
                print(cnt)
                exit()
            else:
                al.popleft()
                cnt += 1
    elif len(al) >= 1:
        time += al[0]
        if time > K:
            print(cnt)
            exit()
        else:
            al.popleft()
            cnt += 1
    elif len(bl) >= 1:
        time += bl[0]
        if time > K:
            print(cnt)
            exit()
        else:
            bl.popleft()
            cnt += 1
    else:
        print(cnt)
        break

Submission status: Wrong Answer

Solution code:
def main():
    N, M, K = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]
    B = [int(x) for x in input().split()]

    # make sure A is always smaller than B
    if N > M:
        N, M = M, N
        A, B = B, A

    import itertools
    import bisect
    A = list(itertools.accumulate(A))
    B = list(itertools.accumulate(B))
    if A[-1] + B[-1] <= K:
        print(N+M)
        return
    ans = bisect.bisect_right(B, K)  # use B only
    for i in range(len(A)-1, -1, -1):
        target = K - A[i]
        if target > 0:
            j = bisect.bisect_right(B, target)
            ans = max(ans, i+j+1)
    print(ans)
 
 
if __name__ == '__main__':
    import sys
    sys.setrecursionlimit(10000)
    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()))
Acount = 0
Bcount = 0

for i in range(N+M):

    if N != 0 and M != 0:
        if A[Acount] < B[Bcount]:
            if K > A[Acount]:
                K = K - A[Acount]
                Acount = Acount + 1
                N = N-1
        elif A[Acount] > B[Bcount]:
            if K > B[Bcount]:
                K = K - B[Bcount]
                Bcount = Bcount +1
                M = M-1
    elif N == 0 and M != 0:
        if K > B[Bcount]:
                K = K - B[Bcount]
                Bcount = Bcount +1
                M = M-1
    elif N != 0 and M == 0:
        if K > A[Acount]:
            K = K - A[Acount]
            Acount = Acount +1
            N = N-1
                

print(Acount + Bcount)

Submission status: Wrong Answer

Solution code:
str1 = input().strip().split()
str_a = input().strip().split()
str_b = input().strip().split()

a_kazu = int(str1[0])
b_kazu = int(str1[1])
jikan_ = int(str1[2])

str_a_count = 0
str_b_count = 0
count = 0

for num in range(a_kazu + b_kazu):
    try:
      if int(str_a[str_a_count]) < int(str_b[str_b_count]):
        jikan_ = jikan_ - int(str_a[str_a_count])
        str_a_count = str_a_count + 1
        count = count + 1
        if jikan_ < 0:
          break
      else:
        jikan_ = jikan_ - int(str_b[str_b_count])
        str_b_count = str_b_count + 1
        count = count + 1
        if jikan_ < 0:
          break
    except:
      try:
        jikan_ = jikan_ - int(str_a[str_a_count])
        str_a_count = str_a_count + 1
        count = count + 1
        if jikan_ < 0:
          break
      except:
        jikan_ = jikan_ - int(str_b[str_b_count])
        str_b_count = str_b_count + 1
        count = count + 1
        if jikan_ < 0:
          break
print(count - 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 = a[::-1]
b = b[::-1]
sum, ans = 0, 0
while(len(a)>0 and len(b)>0):
    sum+=min(a[-1],b[-1])
    if sum>k:
        break
    else:
        ans+=1
        if(a[-1] < b[-1]):
            a.pop()
        else:
            b.pop()
if(sum<k and len(a)!=0):
    for i in range(len(a)):
        sum+=a[-1]
        if sum>k:
            break
        else:
            ans+=1
            a.pop()
if(sum<k and len(b) !=0):
    for i in range(len(b)):
        sum+=b[-1]
        if sum>k:
            break
        else:
            ans+=1
            b.pop()
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a = input().split(" ")
lista = [int(n) for n in a]
b = input().split(" ")
listb = [int(n) for n in b]
time = 0
count = 0
if sum(lista)+sum(listb)<=time:
  print(m+n)
while k>=time:
  if (len(lista)>0 and len(listb)>0 and lista[0]>=listb[0]) or (len(listb)>0 and len(lista)==0):
    time+=listb.pop(0)
    count+=1  
  elif (len(lista)>0 and len(listb)>0 and listb[0]>=lista[0]) or (len(lista)>0 and len(listb)==0):
    time+=lista.pop(0)
    count+=1
  else:
    count+=1
    break
print(count-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()))
Ain = 0
Bin = 0
check = False
if(min(A[0],B[0])>K):
    print(0)
    exit()
if(sum(A)+sum(B)<=K):
    print(N+M)
    exit()
while K>0:
    if(Ain != N and Bin !=M): 
        if(A[Ain] < B[Bin]):
            if(K-A[Ain]<0):
                break
            else:
                K-=A[Ain]
                Ain += 1
        elif(A[Ain]>B[Bin]):
            if(K-B[Bin]<0):
                break
            else:
                K-=B[Bin]
                Bin += 1
        
    elif((Ain == N) and (Bin == M)):
        check = True
        break
    elif(Ain==N):
        if(K-B[Bin]<0):
            break
        else:
            K -= B[Bin]
            Bin += 1
    elif(Bin==M):
        if(K-A[Ain]<0):
            break
        else:
            K -= A[Ain]
            Ain += 1
print(Ain+Bin)

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    import collections
    N, M, K = [int(item) for item in input().split()]
    As = collections.deque([int(item) for item in input().split()])
    Bs = collections.deque([int(item) for item in input().split()])

    res = 0
    time = 0

    while time <= K:
        if not As and not Bs:
            break
        elif not As:
            time += Bs.popleft()
            res +=1
        elif not Bs:
            time += As.popleft()
            res += 1
        else:
            a = As[0]
            b = Bs[0]

            if a <= b:
                time += As.popleft()
            elif Bs:
                time += Bs.popleft()
            res += 1  
        # print(res, time)
        # print(As)
        # print(Bs)

    if time > K:
        print(res -1)
    else:
        print(res)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
count=0
i=0
j=0
while count<=k:
  if a[-1]==10**10 and b[-1]==10**10 or min(a[i],b[j])>=k-count:
    break
  else:
    if a[i]<b[j] and a[i]<=k-count:
      count+=a[i]
      if i+2>len(a):
        a.append(10**10)
        i+=1
      else:
        i+=1
    else:
      count+=b[j]
      if j+2>len(b):
        b.append(10**10)
        j+=1
      else:
        j+=1
    
print(i+j)