Problem:


Score : 300 points

Problem Statement

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

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

Consider the following action:

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

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

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

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

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

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

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

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

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

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

Sample Output 3

0

Watch out for integer overflows.



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


Sample output:
3

Submission status: Wrong Answer

Solution code:
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,M,K = LI()
A = LI()[::-1]
B = LI()[::-1]
ans,_sum = 0,0
for _ in range(N+M):
    if len(A)==0 and len(B)==0:
        break
    if len(A)==0:
        temp = B.pop()
        _sum += temp
    elif len(B)==0:
        temp = A.pop()
        _sum += temp
    else:
        if A[-1]<=B[-1]:
            temp = A.pop()
            _sum += temp
        else:
            temp = B.pop()
            _sum += temp
    if _sum>K:
        break
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    
    cost = 0
    count = 0
    while True:
        a = A[0] if len(A) > 0 else 10**9
        b = B[0] if len(B) > 0 else 10**9
        if a < b:
            if a + cost > K:
                break
            cost += a
            A = A[1:]
        else:
            if b + cost > K:
                break
            cost += b
            B = B[1:]

        count += 1
    
    print(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

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

time = 0
count = 0

while time <= K:
    a = 1000000001
    b = 1000000001
    if len(A) > 0:
        a = A.pop()
    if len(B) > 0:
        b = B.pop()

    if a < b:
        B.append(b)
        time += a
    else:
        A.append(a)
        time += b
    count += 1

print(count - 1)

Submission status: Wrong Answer

Solution code:
# 初期入力
import sys
input = sys.stdin.readline
N,M,K = (int(i) for i in input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C =A+B
C.sort()
read_time =0
ans =0
for i in range(N+M):
    if read_time +C[i] <= K:
        read_time +=C[i]
        ans +=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()))

cntA = 0
cntB = 0
time = 0
ans = 0
while time <= K:
    if ans >= N+M:
        break
    if (cntB == M-1 and cntA <= N-1) or (cntA <= N-1 and A[cntA] <= B[cntB]):
        time += A[cntA]
        cntA += 1
    else:
        time += B[cntB]
        cntB += 1
    if time <= K:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

n, m, k = map(int, input().split())
INF = 10**18
A = list(map(int, input().split()))+[INF]
B = list(map(int, input().split()))+[INF]
A = deque(A)
B = deque(B)
total = 0
cnt = 0
while total <= k:
    if A[0] > B[0]:
        b = B.popleft()
        total += b
    else:
        a = A.popleft()
        total += a
    cnt += 1
if cnt > INF:
    print(n+m)
else:
    print(cnt-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()))
from collections import deque
a=deque(A)
b=deque(B)
t=0
ans=0
while (1):
  if not a:
    a.append(10**10)
  if not b:
    b.append(10**10)
  if a[0]>b[0] and t+b[0]<=K:
    t+=b.popleft()
  elif b[0]>a[0] and t+a[0]<=K:
    t+=a.popleft()
  else:
    break
  ans+=1
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
while (A and K - A[-1] >= 0) or (B and K - B[-1] >= 0):
    if not A:
        K -= B[-1]
        B.pop()
    elif not B:
        K -= A[-1]
        A.pop()
    elif A[-1] >= B[-1]:
        K -= B[-1]
        B.pop()
    else:
        K -= A[-1]
        A.pop()
    ans += 1
    # print(K)
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()))

aidx = 0
bidx = 0
time = 0
judge = True
cnt = 0
while judge:
    if aidx < N and bidx < M:
        if A[aidx] < B[bidx]:
            time += A[aidx]
            aidx += 1
        else:
            time += B[bidx]
            bidx += 1
    else:
        if aidx < N:
            time += A[aidx]
            aidx += 1
        elif bidx < M:
            time += B[bidx]
            bidx += 1
        else:
            break
    if time <= K:
        cnt += 1
    else:
        break

print(cnt)

Submission status: Wrong Answer

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

N,M,K=(int(x) for x in input().rstrip('\n').split())
As=[int(x) for x in input().rstrip('\n').split()]
Bs=[int(x) for x in input().rstrip('\n').split()]
res = 0
now = 0
for i in range(N+M):
  if len(As)>0 and len(Bs)>0:
    a = As[0]
    b = Bs[0]
    if a>b:
      now += b
      del Bs[0]
    else:
      now += a
      del As[0]
  elif len(As) ==0:
    now += Bs[0]
    del Bs[0]
  else:
    now += As[0]
    del As[0]
  if now > K:
    break
  res += 1
print(res)

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
i = 0
j = 0

while True:
  #print(i,j)
  if k <= 0 or k < min(a[i],b[j]) :
    break
  else:
    if i != n - 1 and j != m - 1:
      if a[i] >= b[j]:
        k = k - b[j]
        j += 1
        c += 1
        if len(b) == j:
          j -= 1
      else:
        k = k - a[i]
        i += 1
        c += 1
        if len(a) == i:
          i -= 1
    else:
      if a[i] == n - 1:
        k = k - b[j]
        j += 1
        c += 1
        if len(b) == j:
          j -= 1
      else:
        k = k - a[i]
        i += 1
        c += 1
        if len(a) == i:
          i -= 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()))
cost = 0
ans = 0
pa = 0
pb = 0
while cost <= K:
	if pa < N and pb < M:
		if A[pa] <= B[pb]:
			cost += A[pa]
			pa += 1
		else:
			cost += B[pb]
			pb += 1
		ans += 1
	elif pa < N:
		cost += A[pa]
		pa += 1
		ans += 1
	elif pb < M:
		cost += B[pb]
		pb += 1
		ans += 1
	else:
		ans += 1
		break;
print(ans-1)

Submission status: Wrong Answer

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

finalres = 0
res1 = 0
r1 = 0
t = 0
while r1 < len(dat1):
    if t + dat1[r1] <= k:
        res1 += 1
        t += dat1[r1]
        r1 += 1
    else:
        break

#print("r1", r1, t)
finalres = r1
res2 = 0
r2 = 0
while r2 < len(dat2) and r1 > 0:
    if t + dat2[r2] <= k:
        res2 += 1
        t += dat2[r2]
        r2 += 1
        finalres = max(finalres, r1+r2)
    else:
        r1 -= 1
        t -= dat1[r1]

print(finalres)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))+[10**10]
B = list(map(int, input().split()))+[10**10]
ans = 0
a = 0
b = 0
while True:
  if A[a] > K and B[b] > K:
    break
  else:
    if K >= A[a] and A[a] < B[b]:
      K -= A[a]
      ans += 1
      a += 1
    elif K >= B[b] and B[b] < A[a]:
      K -= B[b]
      ans += 1
      b += 1
    else:
      if A[a+1] < B[b+1]:
        K -= A[a]
        ans += 1
        a += 1
      else:
        K -= B[b]
        ans += 1
        b += 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()))
ans=0
while 0<len(A)+len(B):
    if K<0: ans-=1;break
    if 0<len(A) and 0<len(B):
        if A[0]<B[0]:K-=A[0];A.pop(0)
        else: K-=B[0];B.pop(0)
    elif 0<len(A):
        K-=A[0];A.pop(0)
    else:
        K-=B[0];B.pop(0)
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
#import string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    n,m,k = map(int, stdin.readline().rstrip().split())
    A = list(map(int, stdin.readline().rstrip().split()))
    B = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    ans = 0
    ab = A + B
    ab.sort()
    time = 0
    for i in range(n+m):
        time += ab[i]
        if time > k:
            print(ans)
            exit()
        else:
            ans += 1

    print(ans)
    exit()






if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

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

ans = 0

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

Submission status: Wrong Answer

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

count = 0

mins = 0
Al.append(10 ** 100)
Bl.append(10 ** 100)
ap = 0
bp = 0

while(1):
    if mins + min(Al[ap], Bl[bp]) <= M:
        count += 1
        mins += min(Al[ap], Bl[bp])
        if Al[ap] > Bl[bp]:
            bp += 1
        else:
            ap += 1
    else:
        break
print(count)

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]

#print(a)
#print(b)
ans = 0
while k >= 0:
    if b == [] and a == []:
        break
    elif b == [] and a != []:
        k -= a.pop()
        ans += 1
        continue
    elif a == [] and b != []:
        k -= b.pop()
        ans += 1
        continue
    if a[-1] > b[-1]:
        k -= b.pop()
        ans += 1
    else:
        k -= a.pop()
        ans += 1
    #print(k, a,b)
    

if k < 0:
    print(ans - 1)
    exit()
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 
c = 0
time = 0
for i in range(m+n):
    if a_i >= n:
        time += b[b_i]
        b_i += 1
        c += 1
    
    elif b_i >= m:
        time += a[a_i]
        a_i += 1
        c += 1
    
    elif a[a_i] < b[b_i]:
        time += a[a_i]
        a_i += 1
        c += 1
    
    elif a[a_i] >= b[b_i]:
        time += b[b_i]
        b_i += 1
        c += 1
    
    
    
    if time > k:
        c -= 1
        break
        
print(c)

Submission status: Wrong Answer

Solution code:
N,M,K = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
from collections import deque
da = deque(a)
db = deque(b)
aa = da.popleft()
bb = db.popleft()
count = 0
for i in range(N+M):
    if aa <= bb:
        if K - aa < 0 :
            break
        count += 1
        K -= aa
        if da:
            aa = da.popleft()
        else:
            aa = 10**10
    else:
        if K - bb < 0 :
            break
        count += 1
        K -= bb
        if db:
            bb = db.popleft()
        else:
            bb = 10**10
print(count)

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
for i in range(ka):
    kk = k - al_su[i]
    kb = bisect.bisect(bl_su,kk)
    kc = max(kc,ka+kb)

print(kc)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
N, M, K = map(int, input().split())
A = deque(list(map(int, sys.stdin.readline().split())))
B = deque(list(map(int, sys.stdin.readline().split())))
ans = 0
MIN = 0

if sum(A) + sum(B) <= K:
    print(N + M)
    exit()

while MIN < K:
    if len(A) > 0 and len(B) > 0:
        if A[0] <= B[0]:
            MIN += A.popleft()
            ans += 1
        else:
            MIN += B.popleft()
            ans += 1
    elif len(A) == 0 and len(B) > 0:
        MIN += B.popleft()
        ans += 1
    else:
        MIN += A.popleft()
        ans += 1
print(ans - 1)

Submission status: Wrong Answer

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

i = j = 0
books = 0
while i < n or j < m:
	if i < n and j < m:
		if a[i] <= b[j]:
			if a[i] <= k:
				k -= a[i]
				i += 1
				books += 1
			else:
				i = n
		else:
			if b[j] <= k:
				k -= b[j]
				j += 1
				books += 1
			else:
				j = m
	elif i < n:
		if a[i] <= k:
			k -= a[i]
			i += 1
			books += 1
		else:
			i = n
	elif j < m:
		if b[j] <= k:
			k -= b[j]
			j += 1
			books += 1
		else:
			j = m
	else:
		break
print(books)

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 heapq import heapify, heappop, heappush

heap = []
heapify(heap)

for a in A:
    heappush(heap, a)
for b in B:
    heappush(heap, b)

cnt = 0
t = 0
while t < K:
    x = heappop(heap)
    t += x

    if t <= K:
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int, input().split())
a=list(map(int,input().split()))+[10**9+1]
b=list(map(int,input().split()))+[10**9+1]
i=0
j=0
cnt=0
while(True):
    if(a[i]<=b[j]):
        k=k-a[i]
        i+=1
    else:
        k=k-b[j]
        j+=1
    if(k<0):
        break
    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
i=0
j=0
a.append(10000000000)
b.append(10000000000)
while True:
    if i==n and j==m:
        break
    elif a[i]<=b[j]:
        if k-a[i]<0:
            break
        k-=a[i]
        ans+=1
        i+=1
    elif a[i]>b[j]:
        if k-b[j]<0:
            break
        k-=b[j]
        ans+=1
        j+=1
print(ans)

Submission status: Wrong Answer

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

x=list(map(int,input().split()))

i=0
j=0
c=0
p=0
l=l[::-1]
x=x[::-1]

while len(l) or len(x):

    if len(l)>0 and len(x)>0:

        z=min(l[-1],x[-1])
        if c+z<=k:
            c+=z
            if z==l[-1]:
                l.pop()
            else:
                x.pop()
            p+=1
        else:
            break
    elif len(l)>0 and len(x)==0:

        if c+l[-1]<=k:
            p+=1
            l.pop()
        else:
            break
    elif len(l)==0 and len(x)>0:

        if c+x[-1]<=k:
            p+=1
            x.pop()
        else:
            break
print(p)

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

# stopper
A.append(10**9 + 1)
B.append(10**9 + 1)

ai = 0
bi = 0
total = 0

while total <= K:
    if A[ai] < B[bi]:
        total += A[ai]        
        ai += 1
    else:
        total += B[bi]
        bi += 1

print(ai + bi-1)

Submission status: Wrong Answer

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

books   = 0
minutes = 0

while (len(ai) + len(bi)) != 0:
    if len(ai) != 0 and len(bi) != 0:
        if ai[0] <= bi[0]:
            if minutes + ai[0] > k: break

            books += 1
            minutes += ai[0]
            ai = ai[1:]
        else:
            if minutes + bi[0] > k: break

            books += 1
            minutes += bi[0]
            bi = bi[1:]

    else:
        if len(ai) == 0:
            if minutes + bi[0] > k: break

            books += 1
            minutes += bi[0]
            bi = bi[1:]
        else:
            if minutes + ai[0] > k: break

            books += 1
            minutes += ai[0]
            ai = ai[1:]

print(books)

Submission status: Wrong Answer

Solution code:
def main():

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

    t = 0
    i, j = 0, 0
    ans = 0
    while t < K:
        if i < len(A) and j < len(B):
            if A[i] <= B[j]:
                if t + A[i] <= K:
                    t += A[i]
                    i += 1
                    ans += 1
                else:
                    return ans
            else:
                if t + B[j] <= K:
                    t += B[j]
                    j += 1
                    ans += 1
                else:
                    return ans
        elif i < len(A):
            if A[i] + t <= K:
                ans += 1
                t += A[i]
                i += 1
            else:
                return ans
        elif j < len(B):
            if B[j] + t <= K:
                ans += 1
                t += B[j]
                j += 1
            else:
                return ans
        else:
            return ans
    return ans

if __name__ == '__main__':
    print(main())

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

ans = 0
ai = 0
bi = 0
t = 0
while t < k and (ai < len(A) or bi < len(B)):
  if ai < len(A) and bi < len(B):
    a = A[ai]
    b = B[bi]
    if a < b:
      ai += 1
      t += a
      if t <= k:
        ans += 1
    else:
      bi += 1
      t += b
      if t <= k:
        ans += 1
  elif ai < len(A):
    t += A[ai]
    ai += 1
    if t <= k:
      ans += 1
  else:
    t += B[bi]
    bi += 1
    if t <= k:
      ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
N, M , lim = mi()

A = li()
B = li()

A += [float('Inf')]
B += [float('Inf')]
ind_a = 0 
ind_b = 0

cnt = ans = 0
while True:
    if A[ind_a] > B[ind_b]:
        if cnt + B[ind_b] <= lim:
            ans += 1
            cnt += B[ind_b]
            if ind_b != M:
                ind_b += 1
        else:
            break
    elif A[ind_a] < B[ind_b]:
        if cnt + A[ind_a] <= lim:
            ans += 1
            cnt += A[ind_a]
            if ind_a != N:
                ind_a += 1
        else:
            break
    else:
        if ind_a == N and ind_b == M:
            break
        elif ind_a == N:
            if cnt + B[ind_b] <= lim:
                ans += 1
                cnt += B[ind_b]
                if ind_b != M:
                    ind_b += 1
            else:
                break
        elif ind_b == M:
            if cnt + A[ind_a] <= lim:
                ans += 1
                cnt += A[ind_a]
                if ind_a != N:
                    ind_a += 1
            else:
                break
        else:
            if A[ind_a+1] >= B[ind_b+1]:
                if cnt + B[ind_b] <= lim:
                    ans += 1
                    cnt += B[ind_b]
                    if ind_b != M:
                        ind_b += 1
                else:
                    break
            else:
                if cnt + A[ind_a] <= lim:
                    ans += 1
                    cnt += A[ind_a]
                    if ind_a != N:
                        ind_a += 1
                else:
                    break

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

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

A_acum = list(itertools.accumulate(A))
B_acum = list(itertools.accumulate(B))

ans = 0
for i in range(N):
    for j in range(M):
        t = A_acum[i] + B_acum[j]
        if t <= K:
            ans = max(ans, i+j+2)
        else:
            break

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()))
A = deque(A)
B = deque(B)
t = 0
ans = 0
while t<=K:
    if A and B:
        if A[0] <= B[0] and A:
            t += A.popleft()
        elif A[0] > B[0] and B:
            t += B.popleft()
        ans += 1
    elif not A and B:
        t += B.popleft()
        ans += 1
    elif A and not B:
        t += A.popleft()
        ans += 1
    else:
        ans += 1
        break
print(ans-1)

Submission status: Wrong Answer

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

sub = 0
cnt = 0
while sub <= k:
    a, b = A.pop(), B.pop()
    if a <= b:
        if sub + a > k:
            break
        sub += a
        cnt += 1
        B.append(b)
    else:
        if sub + b > k:
            break
        sub += b
        cnt += 1
        A.append(a)
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
while k > 0:
    if len(a) > 0 and len(b) > 0:
        if a[0] < b[0]:
            if k >= a[0]:
                k -= a.pop(0)
                ans += 1
            else:
                break
        else:
            if k >= b[0]:
                k -= b.pop(0)
                ans += 1
            else:
                break
    elif len(a) > 0 and len(b) == 0:
        if k >= a[0]:
            k -= a.pop(0)
            ans += 1
        else:
            break
    elif len(a) == 0 and len(b) > 0:
        if k >= b[0]:
            k -= b.pop(0)
            ans += 1
        else:
            break
    else:
        break

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()))
t=0
ans=0
aq=deque(a)
bq=deque(b)
aq.append(k)
bq.append(k)
while t<k:
    if aq[0]<=bq[0]:
        t+=aq.popleft()
    else:
        t+=bq.popleft()
    if t<=k:
        ans+=1
print(ans)

Submission status: Wrong Answer

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

  books = A + B;

  books.sort()

  elapsed = 0
  ans = 0

  for v in books:
    elapsed += v

    if(elapsed > K):
      break

    ans += 1
      
  print(ans)


if __name__ == "__main__":
  main()

Submission status: Wrong Answer

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

sumz = 0
count = 0
idA = 0
idB = 0
while sumz <= K and idA < N and idB < M:
    if bookA[idA] < bookB[idB]:
        sumz += bookA[idA]
        idA += 1
    else:
        sumz += bookB[idB]
        idB += 1

    if sumz <= K:
        count += 1

if idA < N and sumz <= K:
    while idA < N and sumz + bookA[idA] <= K:
        sumz += bookA[idA]
        idA += 1
        count += 1

if idB < M and sumz <= K:
    while idB < M and sumz + bookB[idB] <= K:
        sumz += bookB[idB]
        idB += 1
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

ans = 0
for i, x in enumerate(acc_a, 1):
  if x > k:
    break
  for j, y in enumerate(acc_b, 1):
    if x + y > k:
      break
    ans = max(ans, i + 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()))

ans = 0
num_n = 0
num_m = 0
time = 0
while ans < n+m:
  if num_n == n:
    tmp = b[num_m]
    num_m += 1
  elif num_m == m:
    tmp = a[num_n]
    num_n += 1
  else:
    if a[num_n] >= b[num_m]:
      tmp = b[num_m]
      num_m += 1
    else:
      tmp = a[num_n]
      num_n += 1
      
  if time + tmp <= k:
    time += tmp
    ans += 1
  else:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = list(map(int, input().split()))
# a = list(map(int, input().split()))
#
#  abc = [int(input()) for i in range(5)]
#a = int(input())
# w = list(map(int, input().split()))
#n, k = list(map(int, input().split()))
#a = list(map(int, input().split()))
# data = [list(map(int, input().split())) for i in range(n)]
#q = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# ab_sorted = sorted(ab, key=lambda x: x[0])
#bc = [list(map(int, input().split())) for i in range(q)]
# print(min(15*n, 100*(n//10+1), 100*(n//10)+15*(n % 10)))
total = 0
ai = 0
bi = 0
count = 0
while total < k:
    if ai < n and bi < m:
        if a[ai] <= b[bi]:
            total += a[ai]
            ai += 1
        else:
            total += b[bi]
            bi += 1
    elif ai >= n and bi < m:
        total += b[bi]
        bi += 1
    elif ai < n and bi >= m:
        total += a[ai]
        ai += 1
    else:
        break

    # print(total)
    if total <= 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()))
import itertools
x = list(itertools.accumulate(a))
y = list(itertools.accumulate(b))

ans = 0
import bisect
for i in range(n):
    buf = 0
    if k-x[i]>=0:buf = i+1
    buf += bisect.bisect(y,max(k-x[i],0))
    ans = max(ans,buf)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import decimal
import math
from collections import Counter
import sys
input = sys.stdin.readline

N,M,K=map(int,input().split())
dp=[]*210000
ListA=list(map(int,input().split()))
ListB=list(map(int,input().split()))

total=0
Acnt=0
Bcnt=0
for i in range(N+M):
    if(Acnt>=N):
        total+=ListB[Bcnt]
        Bcnt+=1
    elif(Bcnt>=M):
        total+=ListA[Acnt]
        Acnt+=1
    else:
        if(ListA[Acnt]>ListB[Bcnt]):
            total+=ListB[Bcnt]
            Bcnt+=1
        else:
            total+=ListA[Acnt]
            Acnt+=1

    Cnt=Acnt+Bcnt
    if(total>K):
        Cnt-=1
        break
        
print(Cnt)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
numa = sum(a)
numb = 0
cntb = 0
ans = 0
for i in range(n):
    if numa <= k:
        while cntb < m and numa + b[cntb] <= k:
            numa += b[cntb]
            cntb += 1
        ans = max(ans,n-i+cntb)
    numa -= a[-(i+1)]
print(ans)

Submission status: Wrong Answer

Solution code:

import heapq
from collections import defaultdict, deque
from math import ceil, factorial, gcd
from itertools import accumulate, permutations

import bisect
# ----------

INF = float("inf")
MOD = 10 ** 9 + 7
# ----------

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

readed = 0
ans = 0
while True:
    if not A and not B:
        break
    read = 0
    if A and B:
        if A[0] < B[0]:
            read += A.popleft()
        else:
            read += B.popleft()
    elif A:
        read += A.popleft()
    elif B:
        read += B.popleft()
    if readed + read > K:
        break
    readed += read
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split())) + [float('inf')]
B = list(map(int, input().split())) + [float('inf')]

i, j, ans = 0, 0, 0
while K > 0:
    if i == N and j == M:
        break
    elif A[i] < B[j]:
        K -= A[i]
        i += 1
        ans += 1
    else:
        K -= B[j]
        j += 1
        ans += 1

if K < 0:
    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()))

l = a+b
l.sort()

read = 0
count = 0

for i in range(len(l)):
  if read < k:
    read += l.pop(0)
    count += 1
  else:
    count -= 1
    break
    
print(count)