Problem:


Score : 300 points

Problem Statement

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

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

Consider the following action:

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

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

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

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

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

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

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

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

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

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

Sample Output 3

0

Watch out for integer overflows.



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


Sample output:
3

Submission status: Wrong Answer

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

ans = 0

while k > 0:
  if a < n and b < m:
    if As[a] < Bs[b]:
      minimum = As[a]
      a += 1
    elif As[a] > Bs[b]:
      minimum = Bs[b]
      b += 1
    else:
      i = 1
      while a+i < n and b+i < m:
        if As[a+i] < Bs[b+i]:
          minimum = As[a]
          a += 1
          break
        elif As[a+i] > Bs[b+i]:
          minimum = Bs[b]
          b += 1
          break
        else:
          i += 1
      else:
        if a+i < n:
          minimum = As[a]
          a += 1
        elif b+i < m:
          minimum = Bs[b]
          b += 1
        else:
          minimum = As[a]
          a += 1
  elif a < n:
    minimum = As[a]
    a += 1
  elif b < m:
    minimum = Bs[b]
    b += 1
  else:
    break
  
  if minimum > k:
    break  
  k -= minimum
  ans += 1
print(ans)

Submission status: Wrong Answer

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


def solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]"):
    count = 0
    candidateA = []
    weightA = 0
    for a in A:
        if weightA + a > K:
            break
        else:
            candidateA.append(a)
            weightA += a
    current_count = len(candidateA)

    candidateB = []
    weightB = 0
    terminated=False
    max_count = len(candidateA)
    for b in B:
        if len(candidateA)==0:
            break

        if weightA + weightB + b <= K:
            weightB += b
            candidateB.append(b)
            current_count += 1

        else:
            while weightA + weightB + b > K:
                if len(candidateA)>0:
                    removed = candidateA.pop()
                    weightA -= removed
                    current_count -= 1
                else:
                    terminated=True
            if terminated == True:
                break
            else:
                weightB += b
                candidateB.append(b)
                current_count += 1
        max_count = max(max_count, current_count)

    print(max_count)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, K, A, B)

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()))
time = 0
count = 0
while True:
    i=0
    j =0

    if a[i]>b[j]:
        time += a[i]
        if time > k:
            break
        i +=1
        count+=1
        if count==n+m:
            print(n+m)
            exit()
    else:
        time+= b[j]
        if time > k:
            break
        j +=1
        count+=1
        if count==n+m:
            print(n+m)
            exit()
print(count)

Submission status: Wrong Answer

Solution code:
def main():
	from collections import deque
	n,m,k = map(int,input().split())
	a = deque(map(int,input().split()))
	b = deque(map(int,input().split()))
	ans = 0
	timer = 0
	while timer <= k-1:
		if len(a) == len(b) == 0:
			break
		elif len(a) == 0:
			ans += 1
			timer += b.popleft()
		elif len(b) == 0:
			ans += 1
			timer += a.popleft()
		else:
			if a[0] > b[0] and timer+b[0] <= k:
				ans += 1
				timer += b.popleft()
			elif a[0] <= b[0] and timer+a[0] <= k:
				ans += 1
				timer += a.popleft()
			else:
				break

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

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

ans = 0
while True:
    K = K - min(A[0],B[0])
    if K < 0:
        break
    ans += 1
    if min(A[0],B[0])==A[0]:
        A.pop(0)
        if A == []:
            A.append(10**9+1)
    else:
        B.pop(0)
        if B == []:
            B.append(10**9+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()))

time = 0
ai = 0
bi = 0

while not (n <= ai and bi <= m):
    if ai < n and a[ai] <= b[bi]:
        time += a[ai]
        if k < time:
            break
        ai += 1
    elif bi < m and a[ai] > b[bi]:
        time += b[bi]
        if k < time:
            break
        bi += 1
    
    # if ai >= n and bi >= m:
    #     break
    if n <= ai:
        for i in range(bi, m):
            time += b[i]
            if k < time:
                bi = i
                break
        bi = m
    
    if m <= bi:
        for i in range(ai, n):
            time += a[i]
            if k < time:
                ai = i
                break
        ai = n


# print(time)
# print(ai)
# print(bi)
print(ai + bi)

Submission status: Wrong Answer

Solution code:
n,m,k =map(int,input().split())
arr = [int(x) for x in input().split()]
ar = [int(x) for x in input().split()]
array = arr+ar
array.sort()
su = 0
i=0
cnt=0

while(su<=k and i<len(array)):
    if(array[i]>k):
        break
    su+=array[i]
    i+=1
    cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
acount = 0
bcount = 0

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

curr_time = 0
books = 0
a_books = list(map(int, input().split()))
b_books = list(map(int, input().split()))

while curr_time < limit:
  if acount < a:
    if bcount < b:
      if a_books[acount] < b_books[bcount]:
        if curr_time + a_books[acount] > limit: break
        curr_time += a_books[acount]
        acount += 1
        books += 1
      else:
        if curr_time + b_books[bcount] > limit: break
        curr_time += b_books[bcount]
        bcount += 1
        books += 1
    else: 
      if curr_time + a_books[acount] > limit: break
      curr_time += a_books[acount]
      acount += 1
      books += 1
  else:
    if curr_time + b_books[bcount] > limit: break
    curr_time += b_books[bcount]
    bcount += 1
    books += 1
    
print(books)

Submission status: Wrong Answer

Solution code:
from collections import deque, defaultdict, Counter
N, M, K = (int(i) for i in input().split())  
A = list(map(int, input().split()))
B = list(map(int, input().split()))
da = deque(A)
db = deque(B)

ans = 0
total = 0
while True:
  if len(da) > 0 and len(db) > 0:
    if da[0] >= db[0]:
      total += db.popleft()
    else:
      total += da.popleft()
  elif len(db) > 0:
    total += db.popleft()
  else:
    total += da.popleft()

  if total >= K:
    if total == K:
      ans += 1
    print(ans)
    exit()
  else:
    ans += 1

print(N+M)

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:
    k = k - b[cb]
    count += 1
    cb += 1
    if(cb == len(b)):
      eb = True
  elif eb:
    k = k - a[ca]
    count += 1
    ca += 1
    if(ca == len(a)):
      ea = True
  else:
    if a[ca] <= b[cb]:
      if a[ca] <= k:
        k = k - a[ca]
        count += 1
        ca += 1
        if(ca == len(a)):
          ea = True
      else:
        break
    else:
      if b[cb] <= k:
        k = k - b[cb]
        count += 1
        cb += 1
        if(cb == len(b)):
          eb = True
      else:
        break

print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque as dq


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

    ans = 0
    read_sum = 0
    while A or B:
        if not A:
            ref = B
        elif not B:
            ref = A
        else:
            ref = A if A[0] < B[0] else B

        read_sum += dq.popleft(ref)
        if read_sum > K:
            break
        ans += 1

    print(ans)


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()))
time = 0
C = A + B
C.sort()
for i, v in enumerate(C):
    time += v
    if time > k:
        print(i)
        exit()
print(i+1)

Submission status: Wrong Answer

Solution code:
import collections as deque

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A += B
A.sort()
hon = deque.deque(A)
time = 0
ans = 0

while len(hon) > 0:
    time += hon.popleft()
    if time <= K:
        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()))
import numpy
A = list(numpy.cumsum(numpy.array(a)))
B = list(numpy.cumsum(numpy.array(b)))
A = [i for i in A if i<=k]
B = [i for i in B if i<=k]
n=len(A)
m=len(B)
i,j = 0,m-1
ans=m
while True:
  if i==n or j==-1:
    break
  if B[j]+A[i]<=k:
    ans = max(ans,i+j+2)
    i+=1
  else:
    j-=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()))

book = sorted(A + B)
now = 0
ans = 0

for i in range(len(book)):
    if now > K:
        break
    now += book[i]
    if now > K:
        break
    else:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N,M,K = map(int,input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

bsum = [0]
for b in B:
    bsum.append(bsum[-1]+b)

ans = bisect.bisect_left(bsum,K) -1
asum = 0
for n,a in enumerate(A):
    asum += a
    if asum > K:
        break
    m = bisect.bisect_right(bsum,K-asum)
    if ans < m+n:
        ans = m+ n
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
for i in range(1, N):
    A[i] += A[i-1]
for i in range(1, M):
    B[i] += B[i-1]

ans = 0
for i in range(N):
    b = K-A[i]
    if b < 0:
        break
    j = bisect.bisect_right(B, b)
    if ans < (i+1+j):
        ans = i+1+j
print(ans)

Submission status: Wrong Answer

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

a = 0
b = 0
cnt = 0
sum = 0
while sum <= K:
    tmpsum = sum
    if not A and not B:
        break
    elif not A:
        sum = sum + B[0]
        B = B[1:]
        cnt += 1
    elif not B:
        sum = sum + A[0]
        A = A[1:]
        cnt += 1
    elif A[0] <= B[0]:
        sum = sum + A[0]
        A = A[1:]
        cnt += 1
    else:
        sum = sum + B[0]
        B = B[1:]
        cnt += 1
        
    if sum > K:
        sum = tmpsum
        cnt -= 1
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
    n, m, k = list(map(int, input().split()))
    a_books = list(map(int, input().split()))
    b_books = list(map(int, input().split()))

    minutes = 0
    count = 0
    a_idx = 0
    b_idx = 0
    if a_books[0] > k and b_books[0] > k:
        print(0)
        exit()
    while minutes <= k:
        # print(minutes, a_idx, b_idx)

        if b_idx >= len(b_books) and a_idx >= len(a_books):
            break
        elif b_idx >= len(b_books) or (a_idx < len(a_books) and a_books[a_idx] < b_books[b_idx]):
            minutes += a_books[a_idx]
            a_idx += 1
        elif a_idx >= len(a_books) or (b_idx < len(b_books) and b_books[b_idx] < a_books[a_idx]):
            minutes += b_books[b_idx]
            b_idx += 1
        if minutes > k:
            break
        count += 1
    print(count)



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

total = 0
count = 0
A_idx, B_idx = 0, 0
while K >= total:
  if A_idx < len(A) and B_idx < len(B):
    if A[A_idx] > B[B_idx]:
      total += B[B_idx]
      if total > K:
        break
      count += 1
      B_idx += 1
    else:
      total += A[A_idx]
      if total > K:
        break
      count += 1
      A_idx += 1
  elif A_idx == len(A) and B_idx < len(B):
    total += B[B_idx]
    if total > K:
      break
    count += 1
    B_idx += 1
  elif B_idx == len(B) and A_idx < len(A):
    total += A[A_idx]
    if total > K:
      break
    count += 1
    A_idx += 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
cnt = 0

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

Submission status: Wrong Answer

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

sum=0
num=0
count=0
a.extend(b)
new_a=sorted(a)

for i in range(n+m):
    if sum>=k:
        num-=1
        break
    else:
        sum+=new_a[i]
        num+=1

print(num)

Submission status: Wrong Answer

Solution code:
import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    N, M, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))


    nowtime = 0
    acount = 0
    bcount = 0

    while nowtime <= K:
        if acount < N and bcount < M:
            if A[acount] < B[bcount]:
                nowtime += A[acount]
                acount += 1
            else:
                nowtime += B[bcount]
                bcount += 1
        elif acount == N and bcount == M:
            acount += 1
            break
        else:
            if acount == N:
                nowtime += B[bcount]
                bcount += 1
            else:
                nowtime += A[acount]
                acount += 1


    print(acount+bcount-1)



if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

A=[10**10]*(10**6)
B=[10**10]*(10**6)

for i,a in enumerate(list(map(int,input().split()))):
    A[i]=a
for i,b in enumerate(list(map(int,input().split()))):
    B[i]=b

i=0
j=0
ans=0
ct=0

while i<=N and j<=M:
    if A[i]<B[j]:
        ct+=A[i]
        i+=1
    else:
        ct+=B[j]
        j+=1
    ans+=1

    if ct>K:
        ans-=1
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import bisect

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

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

sa = np.cumsum(a)
sb = np.cumsum(b)

if sa[-1] + sb[-1] <= k:
    print(len(a)+len(b))
    exit(0)

r = 0
for i, saa in enumerate(sa):
    if saa > k:
        continue
    j = bisect.bisect_right(sb, k-saa)
    r = max(r, i+j+1)

print(r)

Submission status: Wrong Answer

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


def readstr():
    return input().strip()


def readint():
    return int(input())


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


def readstrs():
    return input().split()


def main():
    N, M, K = readnums()
    A = list(readnums())
    B = list(readnums())
    aa = [a for a in accumulate(A) if a <= K]
    bb = [b for b in accumulate(B) if b <= K]
    ans = len(aa) + len(bb)
    if not ans:
        print(0)
    elif aa[-1] + bb[-1] <= K:
        print(ans)
    else:
        da = -1
        db = -1
        a = A[:len(aa)]
        b = B[:len(bb)]
        tmp = aa[-1] + bb[-1]
        for _ in range(400001):
            tmp -= max(a[da], b[db])
            ans -= 1
            if tmp <= K:
                print(ans)
                break


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

n, m, k = map(int, sys.stdin.readline().split())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))

time = 0
time_tmp = 0
cnt = 0
while True:
    if len(a) == 0 or len(b) == 0:
        if len(a) == 0:
            if len(b) == 0:
                break
            else:
                time_tmp += b.pop(0)
        else:
            time_tmp += a.pop(0)
    else:
        if a[0] < b[0]:
            # aを読む
            time_tmp += a.pop(0)
        else:
            # bを読む
            time_tmp += b.pop(0)
    if time_tmp > k:
        break
    else:
        time = time_tmp
        cnt += 1
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()))


total = 0
count = 0
point_a = 0
point_b = 0

while total < k:
    if point_a == len(a):
        total += b[point_b]
        point_b += 1
    elif point_b == len(b):
        total += a[point_a]
        point_a += 1
    elif a[point_a] > b[point_b]:
        total += b[point_b]
        point_b += 1
    else:
        total += a[point_a]
        point_a += 1

    count += 1

    if point_a == len(a) and point_b == len(b):
        break

    if total > k:
        count -= 1
        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
used=0
for i in range(N):
    if used+A[i]>K:
        break
    else:
        used+=A[i]
        ans+=1

a_read=ans
b_read=0

for i in range(M):
    if used+B[i]>K:
        break
    else:
        used+=B[i]
        ans+=1
        b_read+=1
tmp=ans

for i in range(a_read):
    if b_read==M:
        break
    used-=A[a_read-1]
    a_read-=1
    tmp-=1
    while True:
        if b_read>M:
            break
        if used+B[b_read]<=K:
            used+=B[b_read]
            tmp+=1
        else:
            break
    ans=max(ans,tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
time = 0
while time <= k and (len(a) != 0 or len(b) != 0):
    if len(a) == 0:
        time += b[0]
        ans += 1
        b.pop(0)
    elif len(b) == 0:
        time += a[0]
        ans += 1
        a.pop(0)
    elif a[0] < b[0]:
        time += a[0]
        ans += 1
        a.pop(0)
    elif b[0] <= a[0]:
        time += b[0]
        ans += 1
        b.pop(0)

if time > k:
    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()))
count = 0
time = 0
while time >= 0 and time <= K:
    if len(A) == 0 and len(B) == 0:
        break
    elif len(A) != 0 and (len(B) == 0 or A[0] <= B[0]):
        if time + A[0] > K:
            break
        count += 1
        time += A[0]
        A = A[1:]
    elif len(B) != 0 and (len(A) == 0 or A[0] > B[0]):
        if time + B[0] > K:
            break
        count += 1
        time += B[0]
        B = B[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()))
t = 0
c = 0
while(t<k or a!=[] or b!=[]):
  if a[0] < b[0]:
    t += a.pop(0)
    c+=1
  else:
    t += b.pop(0)
    c+=1
  if a==[]:a.append(10**9+1)
  if b==[]:b.append(10**9+1)
  if a[0]==10**9+1 and b[0]==10**9+1:
    c+=1
    break
print(c-1)

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

time = 0
count = 0
while(time<K):
  if((len(A_list)==0)and(len(B_list)==0)):
    break
  if(len(A_list)==0):
    time = time + B_list[0]
    #print(B_list[0])
    del B_list[:1]
  elif(len(B_list)==0):
    time = time + A_list[0]
    #print(A_list[0])
    del A_list[:1]  
  elif(A_list[0]<B_list[0]):
    time = time + A_list[0]
    #print(A_list[0])
    del A_list[:1]  
  else:
    time = time + B_list[0]
    #print(B_list[0])
    del B_list[:1]
  if(time<=K):
    count += 1
  #print("time",time)
  
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()))

l = a + b
l_sort = sorted(l)

ans = 0
kingaku = 0
if k >= sum(l):
  print(len(l))
else:
  for i in range(n+m):
      if kingaku > k:
        print(ans - 1)
        break
      else:
        kingaku += l_sort[i]
        ans += 1
        continue

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=0
while(len(A)>0 and len(B)>0 and K>=0):
    if A[0]<=B[0]:
        K-=A[0]
        s+=1
        A.pop(0)
    else:
        K-=B[0]
        s+=1
        B.pop(0)
if K<0:
    print(s-1)
elif len(A)==0:
    while(len(B)>0 and K>=0):
        K-=B[0]
        s+=1
        B.pop(0)
    if K<0:
        print(s-1)
    else:
        print(s)
elif len(B)==0:
    while(len(A)>0 and K>=0):
        K-=A[0]
        s+=1
        A.pop(0)
    if K<0:
        print(s-1)
    else:
        print(s)

Submission status: Wrong Answer

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

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)
B = deque(B)

t = 0
ret = 0
while True:

    if len(A) == 0 and len(B) == 0:
        break
    elif len(A) == 0:
        t += B.popleft()
    elif len(B) == 0:
        t += A.popleft()
    elif A[0] > B[0]:
        t += B.popleft()
    else:
        t += A.popleft()

    ret += 1

    if t == K:
        break

    if t > K:
        ret -= 1
        break

print(ret)

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

c = 0
time = 0

while True:
    if time > k:
        c = c - 1
        print(c)
        break
    elif len(a_list) == 0 and len(b_list) == 0:
        print(c)
        break
    else:
        if len(a_list) == 0:
            c += 1
            time += b_list[0]
            b_list.pop(0)
        elif len(b_list) == 0:
            c += 1
            time += a_list[0]
            a_list.pop(0)
        else:
            if a_list[0] < b_list[0]:
                c += 1
                time += a_list[0]
                a_list.pop(0)
            else:
                c += 1
                time += b_list[0]
                b_list.pop(0)

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
while k>0:
  if not(a==[] or b==[]) and a[0]<=b[0]:
    e=a[0]
    a.pop(0)
    k=k-e
    c+=1

  elif not(a==[] or b==[]) and a[0]>b[0]:
    e=b[0]
    b.pop(0)
    k=k-e
    c+=1

  elif a==[] and b!=[]:
    e=b[0]
    b.pop(0)
    k=k-e
    c+=1
  elif a!=[] and b==[]:
    e=a[0]
    a.pop(0)
    k=k-e
    c+=1    
  elif a==[] and b==[]:
    break

if k>=0:
  print(c)
else:
  print(c-1)

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()))
sum_t = 0
cumsumA = [A[0]]
cumsumB = [B[0]]
ansA = N-1
ansB = M-1
tmp = A[0]
for i in range(1, N):
    tmp = tmp + A[i]
    if tmp > K:
        ansA = i-1
        break
    cumsumA += [tmp]
tmp = B[0]
for i in range(1, M):
    tmp = tmp + B[i]
    if tmp > K:
        ansB = i-1
        break
    cumsumB += [tmp]
if ansA == ansB == 0:
    ans = 0
else:
    ans_t = cumsumA[ansA] + cumsumB[ansB]
    ans = ansA + ansB + 2
    while K < ans_t:
        ai, bi = A[ansA], B[ansB]
        if ai >= bi:
            ans_t -= ai
            ans -= 1
            ansA -= 1
        else:
            ans_t -= bi
            ans -= 1
            ansB -= 1

print(ans)
# print(ansA, ansB)

Submission status: Wrong Answer

Solution code:
from collections import deque

n, m, k = map(int, input().split())
a = deque(map(int, input().split()))
b = deque(map(int, input().split()))
ans = 0
while True:
  if not a and b:
    cnd = b.popleft()
  elif not b and a:
    cnd = a.popleft()
  elif not a and not b:
    break
  elif a[0] < b[0]:
    cnd = a.popleft()
  else:
    cnd = b.popleft()
  if cnd <= k:
    ans += 1
    k -= cnd
  else:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)


def main(input, print):
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    t = [[0 for _ in range(n+1)] for _ in range(m+1)]
    ans = 0
    for j in range(1, n+1):
        t[0][j] = t[0][j-1] + a[j-1]
        for i in range(1, m+1):
            if t[i-1][j] + b[i-1] > k:
                break
            t[i][j] = t[i-1][j] + b[i-1]
            ans = max(ans, i+j)
    print(ans)


if __name__ == '__main__':
    main(sys.stdin.readline, print)

Submission status: Wrong Answer

Solution code:
N,M,K=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a=0
b=0
ans=0
for i in range(N+M):
  if a<N and b<M:
    if A[a]<B[b]:
      K-=A[a]
      a+=1
    elif A[a]>B[b]:
      K-=B[b]
      b+=1
    elif A[a]==B[b]:
      if a<N-1 and b<M-1:
        if A[a+1]<=B[b+1]:
          K-=A[a]
          a+=1
        elif A[a+1]>B[b+1]:
          K-=B[b]
          b+=1
      elif a<N-1:
        K-=A[a]
        a+=1
      elif b<M-1:
        K-=B[b]
        b+=1
      else:
        K-=A[a]
        a+=1
  elif a<N:
    K-=A[a]
    a+=1
  elif b<M:
    K-=B[b]
    b+=1
  else:
    break
  if K>=0:
    ans+=1
print(ans)

Submission status: Wrong Answer

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

import itertools
al_su = list(itertools.accumulate(al))
bl_su = list(itertools.accumulate(bl))

import bisect
ka = bisect.bisect(al_su,k)

kc = 0
if ka !=0:
    for i in range(ka):
        kk = k - al_su[i]
        kb = bisect.bisect(bl_su,kk)
        kc = max(kc,i+1+kb)

else:
    kb = bisect.bisect(bl_su,k)
    kc = max(kc,kb)

print(kc)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right as bl

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

At=[A[0]]
Bt=[B[0]]

for i in range(1,N):
    At.append(At[-1]+A[i])
for j in range(1,M):
    Bt.append(Bt[-1]+B[j])

ans=0
for k in range(N):
    temp=k+1+bl(Bt,K-At[k])
    if K-At[k]>=0:
        ans=max(ans,temp)
print(ans)