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:
from decimal import Decimal
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 len(A) > 0 and len(B) >0 and k>0:
  if A[0] < B[0]:
    k -= A[0]
    A.popleft()
    ans += 1
  else:
    k -= B[0]
    B.popleft()
    ans += 1
while len(A) > 0 and k > 0:
  k -= A[0]
  A.popleft()
  ans += 1
while len(B) > 0 and k > 0:
  k -= B[0]
  B.popleft()
  ans += 1
if k == 0:
  print(ans)
else:
  print(ans-1)

Submission status: Wrong Answer

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

    read = []
    acnt, bcnt = 0, 0

    while sum(read) <= K:
        if acnt >= N and bcnt >= M:
            read.append(30)
            break

        if acnt >= N:
            read.append(B[bcnt])
            bcnt += 1
            continue

        if bcnt >= M:
            read.append(A[acnt])
            acnt += 1
            continue

        if A[acnt] < B[bcnt]:
            read.append(A[acnt])
            acnt += 1
        else:
            read.append(B[bcnt])
            bcnt += 1

    print(len(read) - 1)


resolve()

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()))
ad = deque(a)
ad.append(float('inf'))
bd = deque(b)
bd.append(float('inf'))
count = 0
while True:
    k = k - min(ad[0],bd[0])
    if k < 0 or count == n + m:
        break
    if ad[0] > bd[0]:
        bd.popleft()
    else:
        ad.popleft()
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
N, M, K = map(int, input().split())
A = list(accumulate(list(map(int, input().split()))))
B = list(accumulate(list(map(int, input().split()))))
n = 0
m = 0
for a in A:
  n += 1
  if a >= K:
    break
for b in B:
  m += 1
  if b >= K:
    break
ans = 0
for i in range(n):
  for j in range(m):
    if A[i] + B[j] <= K:
      ans = max(ans, i + j + 2)
print(ans)

Submission status: Wrong Answer

Solution code:
a = [input() for l in range(0,3)]
a1 = [int(p) for p in a[0].split()]
a2 = [int(p) for p in a[1].split()]
a3 = [int(p) for p in a[2].split()]
a4 = a2 + a3
b = sorted(a4)
s = 0
t = 0
while s <= a1[2] and t < len(b):
    s = s + b[t]
    t = t + 1
print(t)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int, input().split())
ln_a = list( map(int, input().split()))
ln_b = list( map(int, input().split()))
a = 0
b = 0
counter = 0
read = ''
while True:
    if k < 0:
        break
        
    if  a >= len(ln_a) and b >= len(ln_b):
        counter += 1
        break
    elif a >= len(ln_a):
        read = 'b'
    elif b >= len(ln_b):
        read = 'a'
    elif ln_a[a] == ln_b[b]:
        if min(ln_a[a:], ln_b[b:]) == ln_a[a:]:
            read = 'a'
        else:
          read = 'b'
        
    elif ln_a[a] < ln_b[b]:
        read = 'a'
    else:
        read = 'b'
    
    if read == 'a':
        
        k = k- ln_a[a]
        a += 1
    else:
        k = k- ln_b[b]
        b += 1
    counter +=1
print(counter -1)

Submission status: Wrong Answer

Solution code:
import collections as cs

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

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

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

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

print(count)

Submission status: Wrong Answer

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

ia = 0
ib = 0
t = 0
while True:
    if ib >= m or ia < n and aa[ia] < bb[ib]:
        t += aa[ia]
        ia += 1
    elif ia >= n or ib < m and aa[ia] > bb[ib]:
        t += bb[ib]
        ib += 1
    else:
        if n - ia > m - ib:
            t += aa[ia]
            ia += 1
        else:
            t += bb[ib]
            ib += 1

    if ia == n and ib == m:
        print(ia + ib)
        exit(0)

    if t >= k:
        print(ia + ib - 1)
        exit(0)

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()))
mini=0
count=0
if A[0]>K and B[0]>K:
    print(0)

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

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
i, j = 0, 0
cnt = 0
while K > 0:
    if i < len(a) and j < len(b):
        book = min(a[i], b[j])
        if book == a[i]:
            i += 1
        else:
            j += 1
    elif i >= len(a) and j >= len(b):
        break
    elif i >= len(a):
        book = b[j]
        j += 1
    elif j >= len(b):
        book = a[i]
        i += 1
    K -= book
    if K >= 0:
        cnt += 1
else:
    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()))

an = 0
bn = 0
time = 0
count = 0

for _ in range(10**6):
    if a[an] < b[bn]:
        time += a[an]
        if an < n-1:
          an += 1
    else:
        time += b[bn]
        if bn < m-1:
          bn += 1
    if time <= k:
      count += 1
    else:
      break

print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque
n, m, k = map(int, input().split())
a = input().split()
b = input().split()
ad = deque()
bd = deque()
for i in range(n):
	ad.append(int(a[i]))
for i in range(m):
	bd.append(int(b[i]))
t = 0
f = 0
c = 0
while f == 0:
	if len(ad) != 0 and len(bd) != 0:
		aa = ad.popleft()
		bb = bd.popleft()
		if aa < bb:
			if t + aa > k:
				f = 1
			else:
				t += aa
				bd.appendleft(bb)
				c += 1
		else:
			if t + bb > k:
				f = 1
			else:
				t += bb
				ad.appendleft(aa)
				c += 1
	elif len(ad) == 0 and len(bd) != 0:
		bb = bd.popleft()
		if t + bb > k:
			f = 1
		else:
			t += bb
			c += 1
	elif len(ad) != 0 and len(bd) == 0:
		aa = ad.popleft()
		if t + aa > k:
			f = 1
		else:
			t += aa
			c += 1
	else:
		f = 1
print(c)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)

def main():
    N, M, K = LI()
    A = LI()
    B = LI()

    i, j = (0, 0)

    ans = 0
    cum = 0

    while True:
        if i < N and j < M:
            if A[i] <= B[j]:
                if cum + A[i] <= K:
                    cum += A[i]
                    i += 1
                    ans += 1
                else:
                    if cum + B[j] <= K:
                        cum += B[j]
                        j += 1
                        ans += 1
                    else:
                        break
            else:
                if cum + B[j] <= K:
                    cum += B[j]
                    j += 1
                    ans += 1
                else:
                    if cum + A[i] <= K:
                        cum += A[i]
                        i += 1
                        ans += 1
                    else:
                        break
        elif i < N:
            if cum + A[i] <= K:
                cum += A[i]
                i += 1
                ans += 1
            else:
                break
        elif j < M:
            if cum + B[j] <= K:
                cum += B[j]
                j += 1
                ans += 1
            else:
                break
        else:
            break

    print(ans)

main()

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

book_counter = 0
read_time = 0
while read_time <= k:
    if a and b:
        if a[0] < b[0]:
            if (a[0] + read_time) <= k:
                read_time += a.popleft()
                book_counter += 1
            else:
                break
        else:
            if (b[0] + read_time) <= k:
                read_time += b.popleft()
                book_counter += 1
            else:
                break
    elif a:
        if (a[0] + read_time) <= k:
            read_time += a.popleft()
            book_counter += 1
        else:
            break
    elif b:
        if (b[0] + read_time) <= k:
            read_time += b.popleft()
            book_counter += 1
        else:
            break
    else:
        break
print(book_counter)

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

lenab=n+m #len(a)+len(b)
r=0
t=0
for ii in range(lenab):
  if n<=0 and m<=0:
    print(r)
    exit()
  elif n>0 and m<=0:
    t0=a.pop(0)
    n-=1
  elif n<=0 and m>0:
    t0=b.pop(0)
    m-=1    
  else:
    if a[0]<b[0]:
      t0=a.pop(0)
      n-=1
    else:
      t0=b.pop(0)
      m-=1
#  print(ii,t,t0,a,b)
  if t+t0>k:
    print(r)
    exit()
  else:
    r+=1
    t+=t0

print(r)

Submission status: Wrong Answer

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

cnt = 0
time = 0
a.append(10**10)
b.append(10**10)
i, j = 0, 0
while time < k or (i != n and j != m):
    if a[i] >= b[j]:
        time += b[j]
        if time > k:
            break
        j += 1
        cnt += 1
    elif a[i] < b[j]:
        time += a[i]
        if time > k:
            break
        i += 1
        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()))



Asum=[0]
for i in A:
  Asum.append(Asum[-1]+i)
  if(Asum[-1]>K):break
    
Bsum=[0]
for i in B:
  Bsum.append(Bsum[-1]+i)
  if(Bsum[-1]>K):break
print(Asum,Bsum)

maxval=len(Asum)-1

for i in range(len(Asum)):
  for j in range(len(Bsum)):
    if Asum[-i-1]+Bsum[j]>K:
      maxval=max(maxval,len(Asum)-1-i+j-1)
      print(i,j)
      break
    elif j==len(Bsum)-1:
      print(i,j)
      maxval=max(maxval,len(Asum)-1-i+j)
      
print(maxval)

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()))
ac, bc = 0,0
time = 0
while True:
  if ac == n and bc == m:break
  if ac == n:
    b = B[bc]
    if time + b > k:
      break
    bc += 1
    time += b
  elif bc == m:
    a = A[ac]
    if time + a > k:
      if time + a > k:break
      ac += 1
      time += a
  else:
    a,b = A[ac],B[bc]
    if time + min(a,b) > k:
      break
    time += min(a,b)
    if a <= b: ac+=1
    else: bc+=1
print(ac+bc)

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 = n
B = 0
if (a[0]>k):
    A = 0
for i in range(1,n):
    a[i] += a[i-1]
    if (a[i]>k):
        A = i
for i in range(1,m):
    b[i] += b[i-1]
if (a[0]>k):
    A = 0
ans = A
if (A==0):
        for i in range(m):
            if (b[i]>k):
                print(i)
                exit()
        print(len(b))
        exit()
while True:
    if (A<0):
        break
    if (B>=m):
        break
    B += 1
    #print(A,B)
    if (a[A-1]+b[B-1] >k):
        B -= 1
        A -= 1
    else:
        ans = max(ans,A+B)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n, m, k = ns()
    a = na()
    b = na()

    a_idx = 0
    b_idx = 0
    ans = 0
    cnt = 0
    while a_idx != n or b_idx != m:
        flga = a_idx != n
        flgb = b_idx != m

        if flga and flgb:
            if a[a_idx] < b[b_idx]:
                if ans + a[a_idx] > k:
                    break
                else:
                    ans += a[a_idx]
                    a_idx += 1
                    cnt += 1
            else:
                if ans + b[b_idx] > k:
                    break
                else:
                    ans += b[b_idx]
                    b_idx += 1
                    cnt += 1
        elif flga:
            if ans + a[a_idx] > k:
                break
            else:
                ans += a[a_idx]
                a_idx += 1
                cnt += 1
        elif flgb:
            if ans + b[b_idx] > k:
                break
            else:
                ans += b[b_idx]
                b_idx += 1
                cnt += 1

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# import io
# import sys

# _INPUT = """\
# 3 4 240
# 60 90 120
# 80 150 80 150
# """
# sys.stdin = io.StringIO(_INPUT)


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


C = []
a = b = 0
while True:

  if a >= len(A):
    C += B[b:]
    break

  if b >= len(B):
    C += A[a:]
    break

  if A[a] < B[b]:
    C.append(A[a])
    a += 1
    continue
  else:
    C.append(B[b])
    b += 1
    continue

# print(C)

ans = 0
k = 0
for c in C:
  k += c
  if k > K: break
  ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
num=0
numa=0
numb=0
if sum(a)+sum(b)<=k:
    ans=m+n
else:
    for i in range(n+m):
        if numa!=n:
            if numb!=m:
                if a[numa]>b[numb]:
                    num+=b[numb]
                    numb+=1
                else:
                    num+=a[numa]
                    numa+=1
            else:
                num+=a[numa]
                numa+=1
        else:
            if numb!=m:
                num+=b[numb]
                numb+=1
            else:
                ans=m+n
                break
        if num>k:
            ans=numa+numb-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(' ')))
a.reverse()
b.reverse()

w=0
t=0
while(1):
    if len(a)>0 and len(b)>0:
        if a[-1]>=b[-1]:
            u=b[-1]
            s=0
        elif a[-1]<b[-1]:
            u=a[-1]
            s=1
        
        if t+u<=k:
            t=t+u
            w+=1
            if s==0:
                q=b.pop(-1)
            elif s==1:
                q=a.pop(-1)
        else:
            break

    elif len(a)>0 and len(b)==0:
        u=a[-1]
        if t+u<=k:
            t=t+u
            w+=1
            q=a.pop(-1)
        else:
            break

    elif len(a)==0 and len(b)>0:
        u=b[-1]
        if t+u<=k:
            t=t+u
            w+=1
            q=b.pop(-1)
        else:
            break
    elif len(a)==0 and len(b)==0:
        break

print(w)

Submission status: Wrong Answer

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

a_i = 0
b_i = 0
cnt = 0

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

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

    if k < 0:
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import deque

n, m, k = [int(e) for e in input().split()]
a = deque([int(e) for e in input().split()])
b = deque([int(e) for e in input().split()])

count = 0
while len(a) > 0 and len(b) > 0:
    if a[0] <= b[0] and a[0] < k:
        k -= a.popleft()
        count += 1
    elif b[0] < a[0] and b[0] < k:
        k -= a.popleft()
        count += 1

while len(a) > 0 and a[0] <= k:
    k -= a.popleft()
    count += 1
while len(b) > 0 and b[0] <= k:
    k -= b.popleft()
    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 = 0

for i in range(n+m):
    if k < 0:
        count -= 1
        break
    elif len(a) == 0:
        k = k - b.pop(0)
        count += 1
    elif len(b) == 0:
        k = k - a.pop(0)
        count += 1
    else:
        if a[0] < b[0]:
            k = k - a.pop(0)
            count += 1
        else:
            k = k - b.pop(0)
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
#from heapq import heappop, heappush
#from collections import OrderedDict, defaultdict
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
from collections import deque
#import numba

def run():
    N, M, K = map(int, sysread().split())
    A = deque(list(map(int, sysread().split())))
    B = deque(list(map(int, sysread().split())))


    ret = 0
    time = 0
    while True:
        if A and B:
            if A[0] > B[0]:
                val = B.popleft()
                time += val
                if time >= K:
                    print(ret)
                    return None
                ret += 1
            else:
                val = A.popleft()
                time += val
                if time >= K:
                    print(ret)
                    return None
                ret += 1
        elif A:
            val = A.popleft()
            time += val
            if time >= K:
                print(ret)
                return
            ret += 1
        elif B:
            val = B.popleft()
            time += val
            if time >= K:
                print(ret)
                return None
            ret += 1
        else:
            print(ret)
            return None


if __name__ == "__main__":
    run()

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[b_count]
    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())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
mix = sorted(A + B)
temp_sum = 0
goal = 0
for i in range(len(mix)):
    temp_sum += mix[i]
    goal = i
    if temp_sum > K:
        print(i)
        exit()
print(goal + 1)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
from numpy import cumsum

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

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

max_idx_a = bisect_right(cumA, k)
ans = 0

for idx_a in range(0, max_idx_a):
    rem = k - cumA[idx_a]
    idx_b = bisect_right(cumB, rem)
    ans = max(ans, idx_a + idx_b + 1)

if max_idx_a == 0:
    ans = bisect_right(cumB, k)

print(ans)

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

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)

    if(A == 10 ** 10 and B == 10 ** 10):
        print(ans)
        break

    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()))
time = 0
book = 0

while True:
    if len(a) >=1 and len(b) >= 1 :
        if a[0] > b[0]:
            if b[0] + time <= k:
                time += b[0]
                book += 1
                del b[0]
            else:
                break
        else:
            if a[0] + time <= k:
                time += a[0]
                book += 1
                del a[0]
            else:
                break
    elif len(a) >=1:
        if a[0] + time <= k:
                time += a[0]
                book += 1
                del a[0]
        else:
            break
    elif len(b) >= 1:
        if b[0] + time <= k:
                time += b[0]
                book += 1
                del b[0]
        else:
            break
    elif len(a) == 0 and len(b) == 0:
        break

print(book)

Submission status: Wrong Answer

Solution code:
import sys
N, M, K = map(int, input().split())
A = [int(n) for n in input().split()]
B = [int(n) for n in input().split()]
time = 0
ans = 0
i = 0
while K > time:
    if len(A) * len(B) != 0:
        if A[0] > B[0]:
            time += B[0]
            del B[0]
            ans += 1
        else:
            time += A[0]
            del A[0]
            ans += 1
    elif len(A) == 0:
        time += B[0]
        del B[0]
        ans += 1
    else:
        time += A[0]
        del A[0]
        ans += 1
    if K < time:
        print(ans-1)
        sys.exit()


print(ans)

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()))
inda = 0
indb = 0
time = 0
ans = 0
while time < k and not(inda == n and indb == m):
    if inda != n and indb != m:
        if A[inda] < B[indb]:
            if time + A[inda] <= k:
                ans += 1
                time += A[inda]
                inda += 1
            else:
                break
        else:
            if time + B[indb] <= k:
                ans += 1
                time += B[indb]
                indb += 1
            else:
                break
    elif inda == n:
        if time + B[indb] <= k:
            ans += 1
            time += B[indb]
            indb += 1
        else:
            break
    elif indb == m:
        if time + A[inda] <= k:
            ans += 1
            time += A[inda]
            inda += 1
        else:
            break
    """
    print(time)
    print(ans)
    print(inda)
    print(indb)
    print('#####')
    """
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
A = list(map(int,input().split()))[::-1]
B = list(map(int,input().split()))[::-1]
ans = 0
s = 0
while A and B:
    if A[-1] >= B[-1]:
        s += B.pop()
        if s >= k:
            exit(print(ans+(s==k)))
        else:
            ans += 1
    else:
        s += A.pop()
        if s >= k:
            exit(print(ans+(s==k)))
        else:
            ans += 1
if A:
    while A:
        s += A.pop()
        if s >= k:
            exit(print(ans+(s==k)))
        else:
            ans += 1
else:
    while B:
        s += B.pop()
        if s >= k:
            exit(print(ans+(s==k)))
        else:
            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()))
A += [float("inf")]
B += [float("inf")]

ans = 0
T = 0
a, b = 0, 0
while True:
    if A[a] <= B[b]:
        T += A[a]
        a += 1
    else:
        T += B[b]
        b += 1
    if T > K:
        break
    ans += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
N,M,L = map(int,input().split())
A = deque(map(int,input().split()))
B = deque(map(int,input().split()))
cnt = 0
while True:
    if L < 0:
        cnt -= 1
        break
    else:
        if len(A) != 0 and len(B) != 0:
            if A[0] < B[0]:
                tmp = A.popleft()
            else:
                tmp = B.popleft()
        elif len(A) != 0 and len(B) == 0:
            tmp = A.popleft()
        elif len(A) == 0 and len(B) != 0:
            tmp = B.popleft()
        else:
            break
        L -= 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()))
ans=0
m=0
i=0
j=0
while m<=k:
    if i<=n-1 and j<=m-1:
        if a[i]>=b[j]:
            ans+=1
            i=i+1
        else:
            ans+=1
            j=j+1
    elif i>=n and j<=m-1:
        ans+=1
        j=j+1
    elif i<=n-1 and j>=m:
        ans+=1
        i=i+1
    else:
        break
print(ans)

Submission status: Wrong Answer

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

index_A=0
index_B=0
time = 0
flag =0
while(time<=K):
  if(index_A == len(A)):
    if(index_B == len(B)):
      flag = 2
      break
    else:
      time += B[index_B]
      index_B += 1
      flag = 1
  elif(index_B == len(B)):
    if(index_A == len(A)):
      flag = 2
      break
    else:
      time += A[index_A]
      index_A += 1
      flag = 0
  elif(A[index_A] == B[index_B]):
      time += A[index_A]
      index_A += 1
      flag = 0
  elif(A[index_A] > B[index_B]):
    time+= B[index_B]
    index_B += 1
    flag = 1
  else: 
    time += A[index_A]
    index_A += 1
    flag = 0
if(flag != 2):
  print(index_A+index_B-1)
else:
  print(index_A+index_B)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
A = [int(p) for p in input().split()]
B = [int(p) for p in input().split()]
count = 0

for _ in range(n+m):
  if A[0] > k and B[0] > k:
    break
  if A[0] < B[0]:
    k -= A.pop(0)
    count += 1
  else:
    k -= B.pop(0)
    count += 1
  if len(A)==0:
    A.append((10**9)+1)
  if len(B)==0:
    B.append((10**9)+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()))
alls = a + b
alls.sort()
count = 0

for i in alls:
  if i<=k:
    count+=1
    k=k-i
print(count)