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:
# coding: utf-8
# Your code here!

import sys

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
total=0

if k < a[0] and k <b[0] :
    print(0)
    sys.exit()



while(0<=k) :
    
    try:
        ai=a[count_a]
    except :
        ai=None
        
    try:
        bi=b[count_b]
    except :
        bi=None
    
    # print("total:",total)
    # print(count_a,":",ai)
    # print(count_b,":",bi)
    
    if ai is not None and bi is not None :
        if ai < bi :
            k -= ai 
            count_a+=1
        else :
            k-=bi
            count_b+=1
            
        total+=1
    
    
    elif ai is not None and bi is None :
        
        k-= ai 
        count_a+=1
        
        total+=1
    
    elif ai is None and bi is not None :
        k-=bi
        count_b+=1
        total+=1
        
    else :

        break

if k < 0 :
    print(total-1)
else :
    print(total)

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

from itertools import accumulate
aa=list(accumulate(a))
bb=list(accumulate(b))

from bisect import bisect_left,bisect

kmax=0
for i in range(n):
    if k<aa[i]:
        break
    kk=k-aa[i]
    k2=min(bisect(bb,kk),m-1)
#    print(i,k2)
    kmax=max(kmax,k2+i+1)

print(kmax)

Submission status: Wrong Answer

Solution code:
from collections import deque

N,M,K = list(map(int, input().split()))
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

if(sum(As) + sum(Bs) <= K):
    print(N + M)
    exit()

Asdq = deque(As)
Bsdq = deque(Bs)

Asdq.append(10**10)
Bsdq.append(10**10)

#print(Asdq)
#print(Bsdq)

ans = 0
time = 0
A = Asdq.popleft()
B = Bsdq.popleft()

while True:
#    print(A)
#    print(B)
#    print()

    if(A >= B):
        time += B
        B = Bsdq.popleft()
        
    else:
        time += A
        A = Asdq.popleft()
    
    if(K >= time):
        ans += 1
    
    else:
        print(ans)
        break

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
s = 0
b_count = 0
for i in range(m):
    if s + b[i] <= k:
        s += b[i]
        ans += 1
        b_count = i
    else:
        break
a_count = 0
while True:
    if a_count < n and s+a[a_count] <= k:
        s += a[a_count]
        a_count += 1
        ans += 1
    else:
        break
now = ans
for i in range(b_count, -1, -1):
    s -= b[i]
    now -= 1
    while True:
        if a_count < n and s +a[a_count] <= k:
            s += a[a_count]
            a_count += 1
            now += 1
        else:
            break
    ans = max(now, ans)
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()))

dummy_min = 0
minute = 0
i = 0
j = 0

while i < n and j < m:
  if alist[i] < blist[j]:
    dummy_min += alist[i]
    if dummy_min >= k:
      break
    minute += alist[i]
    i += 1
  else:
    dummy_min += blist[j]
    if dummy_min > k:
      break
    minute += blist[j]
    j += 1

if dummy_min > k:
  print(i+j)
elif i < n:
  while i < n:
    dummy_min += alist[i]
    if dummy_min >= k:
      break
    minute += alist[i]
    i += 1
  print(i+j)
else:
  while j < m:
    dummy_min += blist[j]
    if dummy_min > k:
      break
    minute += blist[j]
    j += 1  
  print(i+j)

Submission status: Wrong Answer

Solution code:
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
sum = 0
acount = 0
bcount = 0

while(sum < k):
    if acount == len(a) and bcount == len(b):
        break

    elif acount == len(a):
        mi = b[bcount]
        sum += mi
        ans += 1
        bcount += 1

    elif bcount == len(b):
        mi = a[acount]
        sum += mi
        ans += 1
        acount += 1

    else:
        if a[acount] < b[bcount]:
            mi = a[acount]
            sum += mi
            ans += 1
            acount += 1
        else:
            mi = b[bcount]
            sum += mi
            ans += 1
            bcount += 1

if k < sum:
    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()))
time = 0
count = 0
Anum = 0
Bnum = 0
judgea = 0
judgeb = 0
check = 0
while time<=K:
    if judgea == 2 and judgeb ==1:
        break
    
    if A[Anum]>B[Bnum] or judgea == 2:
        time += B[Bnum]
        
        if Bnum+1 >= len(B):
            judgeb = 1
        else:
            Bnum += 1
        count += 1
        check = 1
    if  check != 1 and(A[Anum]<=B[Bnum] or judgeb == 1):
        time += A[Anum]
       
        if Anum+1 >= len(A):
            judgea = 2
        else:
            Anum += 1
        count += 1
    check = 0
if time>K:
    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()))
a.extend(b)

time = 0
count = 0
if a[0] > k:
  print(count)
else:
  for x in a:
    if time > k:
      break
    time += x
    count += 1
  print(count)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_right
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,M,K = map(int, readline().split())
    A = [int(i) for i in readline().split()]
    B = [int(i) for i in readline().split()]

    acc_A = list(accumulate(A))
    acc_B = list(accumulate(B))

    ans = 0
    for i, a in enumerate(acc_A):
        tmp = i + 1
        rest = K - a
        if rest < 1:
            break
        b_ind = bisect_right(acc_B, rest)
        tmp += b_ind

        ans = max(ans, tmp)

    print(ans)
       


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=map(int,input().split())
B=map(int,input().split())
A=list(A)
B=list(B)
C=0
for i in range(len(A)+len(B)):
  if len(A)==0:
    C+=B[0]
    if C>K:
      C=C-B[0]
      break
    else:
      del B[0]
  elif len(B)==0:
    C+=A[0]
    if C>K:
      C=C-A[0]
      break
    else:
      del A[0]
  else:
    C+=min(A[0],B[0])
    if C>K:
      C=C-min(A[0],B[0])
      break
    else:
      if A[0]>B[0]:
        del B[0]
      else:
        del A[0]
print(C)

Submission status: Wrong Answer

Solution code:
from heapq import heapify, heappop, heappush
N, M, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
cur = 0
ans = 0
heapify(A)
heapify(B)
while cur < K and ans < N+M:
    if len(A) != 0 and len(B) != 0:
        a = heappop(A)
        b = heappop(B)
        if a <= b:
            cur += a
            if cur > K:
                break
            heappush(B, b)
            ans += 1
        else:
            cur += b
            if cur > K:
                break
            heappush(A, a)
            ans += 1
    elif len(A) == 0:
        b = heappop(B)
        cur += b
        if cur > K:
            break
        ans += 1
    elif len(B) == 0:
        a = heappop(A)
        cur += a
        if cur > K:
            break
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque


d=deque()
N,M,K=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
B.reverse()
for i in range(len(A)):d.append(A[i])
for i in range(len(B)):d.append(B[i])

sum_time=0
count=0

while True:
    try:
        rigth=d.pop()
        left=d.popleft()
    except:
        sum_time+=rigth
        if sum_time<=K:count+=1
        else:pass
    
    if rigth<left:
        sum_time+=rigth
        if sum_time<=K:count+=1
        else:break
        d.append(left)
    else:
        sum_time+=left
        if sum_time<=K:count+=1
        else:break
        d.append(rigth)

print(count)

Submission status: Wrong Answer

Solution code:
def main():
    N, M, K = map(int, input().split())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    ans = 0
    read_sum = 0
    cnt = 0

    for i, v in enumerate(A):
        if read_sum + v > K:
            break
        read_sum += v
        cnt += 1

    A_i = i

    for i, v in enumerate(B):
        if read_sum + v > K:
            B_i = i
            break
        read_sum += v
        cnt += 1

    B_i = i
    ans = cnt

    while A_i != -1:
        read_sum -= A[A_i]
        cnt -= 1
        A_i -= 1

        for i in range(B_i, M):
            if read_sum + B[i] > K:
                B_i = i
                break
            read_sum += B[i]
            cnt += 1

        ans = max(ans, cnt)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
rem=k
i=0
j=0
k=0
c=list()
count=0
while k<n+m:
	if a[i]<=b[j]:
		c.append(a[i])
		k=k+1
		i=i+1
	else:
		c.append(b[j])
		k=k+1
		j=j+1
	if i==n:
		while j<m:
			c.append(b[j])
			k=k+1
			j=j+1
	if j==m:
		while i<n:
			c.append(a[i])
			k=k+1
			i=i+1
i=0
while i<k and rem>=c[i] :
	rem=rem-c[i]
	i=i+1
	count=count+1
print(count)

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

time=0
a_idx=0
b_idx=0
count=0
while time<K:
    count+=1
    try:
        if a_idx+1==N:
            time+=b[b_idx]
            b_idx+=1
            if time>K:
                count-=1
            continue
        elif b_idx+1==M:
            time+=a[b_idx]
            a_idx+=1
            if time>K:
                count-=1
            continue
        
        
        if a[a_idx]<b[b_idx]:
            time+=a[a_idx]
            a_idx+=1
            
        elif a[a_idx]>b[b_idx]:
            time+=b[b_idx]
            b_idx+=1
        else:
            try:
                a_com=a_idx
                b_com=b_idx
                while True:
                    if a[a_com]>b[b_com]:
                        time+=a[a_idx]
                        a_idx+=1
                        break
                    elif a[a_com]<b[b_com]:
                        time+=b[b_idx]
                        b_idx+=1
                        break
                    a_com+=1
                    b_com+=1
            except:
                time+=a[a_idx]
                a_idx+=1
        if time>K:
            count-=1
                
    except:
        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()))

ca = 0
cb = 0
count = 0
ea = False
eb = False
while k > 0:
  if ea and eb:
    break
  elif ea:
    if b[cb] <= k:
        k = k - b[cb]
        count += 1
        cb += 1
        if(cb == m):
          eb = True
    else:
      break
  elif eb:
    if a[ca] <= k:
        k = k - a[ca]
        count += 1
        ca += 1
        if(ca == n):
          ea = True
    else:
      break
  else:
    if a[ca] <= b[cb]:
      if a[ca] <= k:
        k = k - a[ca]
        count += 1
        ca += 1
        if(ca == n):
          ea = True
      else:
        break
    else:
      if b[cb] <= k:
        k = k - b[cb]
        count += 1
        cb += 1
        if(cb == m):
          eb = True
      else:
        break

print(count)

Submission status: Wrong Answer

Solution code:
n,m,k=list(map(int, input().split()))
a=list(map(int, input().split()))
b=list(map(int, input().split()))
mnt=0
i=1
mb=0
j=1
while mnt<=k and 0<i<n+1:
    mnt+=a[i-1]
    i+=1
if mnt>k:
    i-=2
    mnt-=a[i]
else:
    i-=1

while i>=0:

    while mnt<=k and j<m+1:
        if j==0:
            j=1
        mnt+=b[j-1]
        j+=1
    if mnt>k:
        j-=2
        mnt-=b[j]
    else:
        j-=1
        
    if i+j>mb:
        mb=i+j
    
    mnt-=a[i-1]
    i-=1            
            
            
print(mb)

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 = 0
flg = True

if A[0] > K or B[0] > K:
    print(ans)

else:
    while flg:
        if len(A) == 0 and len(B) == 0:
            flg = False
            
        elif len(A) == 0:
            C = C + B[0]
            B.pop(0)

        elif len(B) == 0:
            C = C + A[0]
            A.pop(0)
            
        elif len(A)!=0 and len(B)!=0 and A[0] > B[0]:
            C = C + B[0]
            B.pop(0)
            
        elif len(A)!=0 and len(B)!=0 and A[0] <= B[0]:
            C = C + A[0]
            A.pop(0)
            
        ans += 1

        if C >= K:
            flg = False

    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()))
h, j = max(A), max(B)
fe = max(h,j)
c = 0
time = 0
while K >= A[0] or K >= B[0]:
    if A[0] < B[0]:
        K -= A.pop(0)
    elif A[0] > B[0]:
        K -= B.pop(0)
    c += 1
    if len(A) == 0:
        A = A + [fe+1]
    if len(B) == 0:
        B = B + [fe+1]
print(c)

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

# cumsum
A_cum = [0] * (N+1)
B_cum = [0] * (M+1)
ap = 0
for i, a in enumerate(A_list):
    A_cum[i+1] = ap + a
    ap += a
bp = 0
for i, b in enumerate(B_list):
    B_cum[i+1] = bp + b
    bp += b

for ai,a in enumerate(A_cum):
    if a > K:
        break

max_cnt = ai-1 
for i in list(range(ai+2))[::-1]:
    a = A_cum[ai]
    for bi,b in enumerate(B_cum):
        if b+a > K:
            break

    max_cnt = max(max_cnt, i+bi-1)

print(max_cnt)

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)

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()))
A.append(10**12)
B.append(10**12)

sig_a = 0
sig_b = 0
ans = 0
flag = 0
L = []
for i in range(N+M):
  if A[sig_a] >= B[sig_b]:
    ans += B[sig_b]
    sig_b += 1
  else:
    ans += A[sig_a]
    sig_a += 1
  if ans > K:
    L.append(i)
    flag += 1
    
if flag >= 1:
  print(min(L))
else:
  print(N+M)

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.sort(reverse=True)

b.sort(reverse=True)

a = deque(a)

b = deque(b)

count = n+m

count_min = sum(a)+sum(b)

while k < count_min:
    if a and b:
        if a[0] >= b[0]:
            count_min -= a[0]
            a.popleft()
        else:
            count_min -= b[0]
            b.popleft()
    elif a:
        count_min -= a[0]
        a.popleft()
    elif b:
        count_min -= b[0]
        b.popleft()
    else:
        print(0)
        exit()
    count -= 1

print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque
def main():
    N, M, K = map(int, input().split())
    A = [int(a) for a in input().split()]
    B = [int(b) for b in input().split()]
    A = deque(A)
    B = deque(B)

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

    ans = tot = 0

    for i in range(4*10**5 + 10):
        a = A[0]
        b = B[0]

        if a < b:
            if tot + a <= K:
                ans += 1
                tot += A.popleft()

        elif a > b:
            if tot + b <= K:
                ans += 1
                tot += B.popleft()

        else:
            if tot + a <= K:
                ans += 1
                tot += A.popleft()

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import bisect
import itertools
n ,m ,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a = list(itertools.accumulate(a))
b = list(itertools.accumulate(b))
A =bisect.bisect_left(a,k)
count=0

if A<n:
  if a[A]==k:
    A+=1
if b[0]>k:
  print(A)
  exit()
if a[0]>k:
  print(bisect.bisect_left(b,k))
  exit()

for i in range(A,0,-1):
  ans=k-a[i-1]
  B =bisect.bisect_left(b,ans)
  if B<m:
    if b[B]==ans:
      B+=1
  count=max(count,i+B)
print(count)

Submission status: Wrong Answer

Solution code:


import sys
import math
import itertools
import collections

def solve(N,M,K,A,B):
    total = 0
    counter = 0
    lis = []
    while True:
        if len(A) == 0:
            lis.extend(B)
            break
        elif len(B) == 0:
            lis.extend(A)
            break
        lis.append(A.pop(0)) if A[0] < B[0] else lis.append(B.pop(0))
    for l in lis:
        total +=l
        if total > K:
            return counter
        else:
            counter += 1
    return counter





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

if __name__ == "__main__":
    main()


    # accumA = [A.pop(0)]
    # accumB = [B.pop(0)]
    # for a,b in zip(A,B):
    #     accumA.append(accumA[-1] + a)
    #     accumB.append(accumB[-1] + b)

Submission status: Wrong Answer

Solution code:
import sys

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

    yomuA = a[0]
    yomuB = b[0]
    ans = []
    
    countA = 0
    countB = 0

    for i in range(n+m):
        if (yomuA < yomuB):
            if (countA < n-1):
                ans.append(yomuA)
                countA += 1
                yomuA = a[countA]
            elif (countA == n-1):
                ans.append(yomuA)
                for j in range(countB, m):
                    ans.append(b[j])
                break
        else:
            if (countB < m-1):
                ans.append(yomuB)
                countB += 1
                yomuB = b[countB]
            elif(countB == m):
                ans.append(yomuB)
                for k in range(countA, n):
                    ans.append(a[k])
                break



    sum_ = 0
    for i in range(len(ans)):
        sum_ += ans[i]
        if (sum_ > k):
            print(i)
            break
        elif(i == len(ans)-1):
            print(i+1)

main()

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_i = 0
b_i = 0
time = 0
counter = 0

while time < k:
    if a_i >= len(a_list) and b_i < len(b_list):
        time += b_list[b_i]
        if time > k:
            break
        counter += 1
        b_i += 1
    elif b_i >= len(b_list) and a_i < len(a_list):
        time += a_list[a_i]
        if time > k:
            break
        counter += 1
        a_i += 1
    elif a_i >= len(a_list) and b_i >= len(b_list):
        break
    else:
        if a_list[a_i] <= b_list[b_i]:
            time += a_list[a_i]
            if time > k:
                break
            counter += 1
            a_i += 1
        else:
            time += b_list[b_i]
            if time > k:
                break
            counter += 1
            b_i += 1

print(counter)

Submission status: Wrong Answer

Solution code:
m,n,size = list(map(int,input().split(" ")))

a = list(map(int,input().split(" ")))
b = list(map(int,input().split(" ")))
temp = []
j = 0
k=0
s = 0
c = 0
for i in range(len(a)+len(b)):
    if j <len(a):
        s += a[j]
        j+=1
        if s>size:
            break
        c += 1
    if k <len(b):
        s+= b[k]
        k+=1
        if s>size:
            break
        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()))

ans = 0

if A[0] < B[0]:
    select = A.pop(0)
else:
    select = B.pop(0)

while select <= K:
    K = K - select
    ans += 1
    if not A and not B:
        break
    elif not A:
        select = B.pop(0)
    elif not B:
        select = A.pop(0)
    else:
        if A[0] < B[0]:
            select = A.pop(0)
        else:
            select = B.pop(0)
        
print(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(10**9+1)
B.append(10**9+1)
run_time = K
count_A = 0
count_B = 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:
A, B, limit_time = list(map(int ,input().split()))
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))

total_time = 0
count = 0

while len(A_list) != 0 or len(B_list) != 0:
  if len(A_list) == 0:
    if total_time + B_list[0] <= limit_time:
      total_time += B_list.pop(0)
      count += 1
    else:
      break
  elif len(B_list) == 0:
    if total_time + A_list[0] <= limit_time:
      total_time += A_list.pop(0)
      count += 1
    else:
      break
  else:
    if A_list[0] <= B_list[0] and total_time + A_list[0] <= limit_time:
      total_time += A_list.pop(0)
      count += 1
    elif B_list[0] <= A_list[0] and total_time + B_list[0] <= limit_time:
      total_time += B_list.pop(0)
      count += 1
    else:
      break
      
print(count)

Submission status: Wrong Answer

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

Asum = [0] + list(accumulate(A))
Bsum = [0] + list(accumulate(B))
ans=0
#print(Asum)
#print(Bsum)
for i in range(len(Asum)):
    if K > Asum[i]:
        #print("a=",i)
        #print("b=",bisect.bisect_right(Bsum, K-Asum[i])-1)
        ans=max(ans,i-1+bisect.bisect_right(Bsum, K-Asum[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.append(10000000000)
b.append(10000000000)
ans = 0
t = 0
a1,b1 = 0,0
while t<k:
    if t+min(a[a1],b[b1])>k: break
    if a[a1]<b[b1]:
        t+=a[a1]
        a1+=1
    else:
        t+=b[b1]
        b1+=1
    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()))
a=[0]*N
b=[0]*M
a[0]=A[0]
b[0]=B[0]
for i in range(N-1):
    a[i+1]=a[i]+A[i]
for i in range(M-1):
    b[i+1]=b[i]+B[i]
diff=2*10**9
count=0
for i in range(N):
    j=bisect.bisect_left(b,K-a[i])-1
    if 0<=K-(a[i]+b[j])<diff:
        diff=K-(a[i]+b[j])
        count=(i+1)+(j+1)
print(count)

Submission status: Wrong Answer

Solution code:
data = [int(k) for k in input().split()]

A = data[0]
B = data[1]
K = data[2]

Abooks = [int(k) for k in input().split()]
Bbooks = [int(k) for k in input().split()]


time = 0
nbOfBooks = 0

while ((time + Bbooks[0]) or (time + Abooks[0]) ) <= K:
	
	if len(Abooks) != 0 and len(Bbooks) != 0:
		
		if Abooks[0] >= Bbooks[0]:
			time += Bbooks[0]
			if len(Bbooks) == 1:
				Bbooks[0] = 10**9+1
			else:
				Bbooks.pop()
			nbOfBooks += 1

		else:
			time += Abooks[0]
			if len(Abooks) == 1:
				Abooks[0] = 10**9+1
			else:
				Abooks.pop()
			nbOfBooks += 1 


print(nbOfBooks)

Submission status: Wrong Answer

Solution code:
import itertools
import bisect

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

a_sum = list(itertools.accumulate(A))
b_sum = list(itertools.accumulate(B))

a_limit = bisect.bisect_left(A, k)
b_limit = bisect.bisect_left(B, k)

ans= 0

for i in range(a_limit):
    for j in range(b_limit):
        if a_sum[i] + b_sum[j] <= k:
            if i + j > ans:
                ans = i + j + 2

print(ans)

Submission status: Wrong Answer

Solution code:

N,M,K = map(int,input().split())
A_lis = list(map(int,input().split()))
B_lis = list(map(int,input().split()))





if A_lis[0]>B_lis[0]:
    status=B_lis[0]
elif  A_lis[0]<B_lis[0]:
    status=A_lis[0]
else:
    status=A_lis[0]
    
    

count=0



for i in range(len(A_lis)+len(B_lis)):
    if K>status:
        if len(A_lis)>0 and len(B_lis)>0:
            if A_lis[0]<B_lis[0]:
                pd=A_lis.pop(0)
                status+=pd
                count+=1
            elif A_lis[0]>B_lis[0]:
                pd=B_lis.pop(0)
                status+=pd
                count+=1
            else:
                pd=A_lis.pop(0)
                status+=pd
                count+=1
        elif len(A_lis)==0:
            pd=B_lis.pop(0)
            status+=pd
            count+=1
        elif len(B_lis)==0:
            pd=A_lis.pop(0)
            status+=pd
print(str(count))

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

i = 0
j = 0

ans = 0
now = 0
while i + j < N + M:
    if i >= N:
        book = B[j]
        j += 1
    elif j >= M:
        book = A[i]
        i += 1
    elif A[i] < B[j]:
        book = A[i]
        i += 1
    else:
        book = B[j]
        j += 1

    if now + book <= K:
        ans +=  1
        now += book
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
#s = input()
#n = int(input())
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
j = 0
l = 0
t = 0
while(t <= k and ((j+l) < (n+m))):
    if(j < n and l < m):
        tt = t + min(a[j], b[l])
        if(tt > k):
            break
        t = tt
        if(a[j] <= b[l]):
            j += 1
        else:
            l += 1
    elif(j == n):
        t += b[l]
        l += 1
    else:
        t += a[j]
        j += 1
print(j+l)

Submission status: Wrong Answer

Solution code:
import sys

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

A = list(map(int, input().split()))
B = list(map(int, input().split()))
lA = len(A)
lB = len(B)

i = 0
j = 0
h = 0
dp = [-1] * 410000
dp[0] = 0
while dp[h] <= K:
    if i >= lA and j >= lB:
        print(lA + lB)
        sys.exit(0)
    h += 1
    #print(h)
    if i < lA:
        dp[h] = dp[h-1] + A[i]
        #print(dp[h])
    else:
        dp[h] = 10 ** 18
    if j < lB:
        if dp[h] > dp[h-1] + B[j]:
            dp[h] = dp[h-1] + B[j]
            #print(dp[h])
            j += 1
        else:
            i += 1
    #print(i,j)

print(h-1)

Submission status: Wrong Answer

Solution code:
import sys
a, b, n = map(int, input().split())
alis = list(map(int, input().split()))
blis = list(map(int, input().split()))
alis.append(sys.maxsize)
blis.append(sys.maxsize)

count = 0
time = 0

ac = 0
bc = 0
while time <= n:
    time += min(alis[ac], blis[bc])
    count += 1
    if alis[ac] < blis[bc]:
        ac += 1
    else:
        bc +=1

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()))
ans = 0
nowK = K
for A_idx in range(len(A)):
    if nowK < A[A_idx]:
        break
    ans += 1
    nowK -= A[A_idx]
for B_idx in range(M):
    if nowK < B[B_idx]:
        break
    ans += 1
    nowK -= B[B_idx]
if A_idx == 0:
    print(ans)
    exit()
tmp_ans = ans
for i in range(A_idx, -1, -1):
    nowK += A[i]
    tmp_ans -= 1
    for j in range(B_idx, M):
        if nowK < B[j]:
            break
        nowK -= B[j]
        tmp_ans += 1
    B_idx = j
    ans = max(tmp_ans, 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()))

a_i= 0
b_i= 0
f = True

if sum(a)+sum(b) <= k:
    print(n+m)
    exit()

for i in range(n+m):
    # print(a_i,b_i,k) 
    if a[a_i] < b[b_i]:
        k -= a[a_i]
        if k < 0:
            break 
        a_i += 1
        if a_i == n:
            for j in range(m):
                k -= b[b_i]
                if k < 0:
                    print(a_i+b_i)
                    exit()
                b_i += 1
    else:
        k -= b[b_i]
        if k < 0:
            break 
        b_i += 1
        if b_i == m:
            for j in range(n):
                k -= a[a_i]
                if k < 0:
                    print(a_i+b_i)
                    exit()
                a_i += 1
    

    

print(a_i+b_i)