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())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.append(19999999999999)
a.append(29999999999999)
b.append(19999999999999)
b.append(29999999999999)

i,j = 0,0
ans = 0
for _ in range(400010):
    
    if a[i] < b[j]:
        k -= a[i]
        i += 1
    elif a[i] > b[j]:
        k -= b[j]
        j += 1
    else:
        if a[i+1] < b[j+1]:
            k -= a[i]
            i += 1
        else:
            k -= b[j]
            j += 1

    if k < 0:
        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()))
ans = 0
end_a = False
end_b = False
while(k - min(a[0], b[0]) >= 0):
    ans += 1
    k -= min(a[0], b[0])
    if a[0] > b[0]:
        del b[0]
    else:
        del a[0]
    if len(a) == 0:
        a = [1e9+1]
        end_a = True
    if len(b) == 0:
        b = [1e9+1]
        end_b = True
    if end_a and end_b:
        break
print(ans)

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

cnt = 0
time = 0
a = A.popleft()
b = B.popleft()

while time < K:
    if a < b:
        time += a
        try:
            a = A.popleft()
        except:
            a = 10**9 + 1
    else:
        time += b
        try:
            b = B.popleft()
        except:
            b = 10**9 + 1
    if time > K:
        break

    cnt += 1

print(cnt)

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

for a in A:
    _A.append(a)
    
for b in B:
    _B.append(b)
    
time = 0
ans = 0
inf = pow(10,9)+1

while True:
    a = inf
    b = inf
    if _A:
        a = _A.popleft()
    if _B:
        b = _B.popleft()
    if a < b:
        time += a
        _B.appendleft(b)
    else:
        time += b
        _A.appendleft(a)
    if time > K:
        break
    ans += 1
    
print(ans)

Submission status: Wrong Answer

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

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, M, K = map(int, readline().split())
A = list(map(int, readline().split()))[::-1]
B = list(map(int, readline().split()))[::-1]

idx_a = 0
idx_b = 0
tot = 0
cnt = 0

while True:
    if len(A) > 0:
        acc_a = A.pop()
    else:
        acc_a = 1 << 60
    if len(B) > 0:
        acc_b = B.pop()
    else:
        acc_b = 1 << 60
    acc = min(acc_a, acc_b)
    if tot + acc <= K:
        cnt += 1
    else:
        break

    tot += min(acc_a, acc_b)
    if acc_a <= acc_b:
        B.append(acc_b)
    else:
        A.append(acc_a)

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

ans = 0
m = 0
for i in A:
  m += i
  if m > K:
    break
  ans += 1

C = [0] * N
C[0] = A[0]
for i in range(1, N):
  C[i] = C[i - 1] + A[i]

D = [0] * M
D[0] = B[0]
for i in range(1, M):
  D[i] = D[i - 1] + B[i]

if ans == 0:
  t = 0
else:
  t = C[ans - 1]

k = ans
n = ans
for i in range(M):
  m = D[i]
  if m > K: break
  while m + t > K:
    n -= 1
    if n >= -1:
      t = 0
      break
    t = C[n]
  ans = max(ans, i + 1 + n)

print(ans)

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

i = 0;  j = 0;  ans = 0;
while K > 0:
    if i >= N and j >= M: break
    if i >= N:
        if B[j] > K: break
        ans += 1
        K -= B[j]
        j += 1
    elif j >= M:
        if A[i] > K: break
        ans += 1
        K -= A[i]
        i += 1
    elif A[i] <= B[j]:
        if A[i] > K: break
        K -= A[i]
        ans += 1
        i += 1
    else:
        if B[j] > K: break
        K -= B[j]
        ans += 1
        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()))
c = 0
i = 0
j = 0
s = 0
while i+j < n+m:
  if i < n and j < m:
    if a[i] < b[j]:
      if s + a[i] <= k:
        s += a[i]
        i += 1
      else:
        break
    else:
      if s + b[j] <= k:
        s += b[j]
        j += 1
      else:
        break
  elif i < n:
    if s + a[i] <= k:
      s += a[i]
      i += 1
    else:
      break
  else:
    if s + b[j] <= k:
      s += b[j]
      j += 1
    else:
      break
print(i+j)

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
tot=0
i=0
j=0
while(i<n and j<m):
    if(a[i]<=b[j]):
        if(tot+a[i]<=k):
            ans+=1;
            tot+=a[i]
            i+=1
        else:
            break
    else:
        if(tot+b[j]<=k):
            ans+=1
            tot+=b[j]
            j+=1
        else:
            break
if(tot<k):
    while(j<m):
        if(tot+b[j]<=k):
            ans+=1
            tot+=b[j]
            j+=1
        else:
            break
    while(i<n):
        if(tot+a[i]<=k):
            ans+=1;
            tot+=a[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()))

s = t = 0
ans = 0
while s < n or t < m:
  if s == n:
    k -= b[t]
    t += 1
  elif t == m:
    k -= a[s]
    s += 1
  elif a[s] <= b[t]:
    k -= a[s]
    s += 1
  elif a[s] > b[t]:
    k -= b[t]
    t += 1
  if k < 0: 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()))
A.append(10**10)
B.append(10**10)
kcnt = 0
acnt = 0
bcnt = 0
Ktmp = 0

for i in range(N+M):
    if A[acnt] > B[bcnt]:
        Ktmp += B[bcnt]
        bcnt += 1
    else:
        Ktmp += A[acnt]
        acnt += 1
    
    if Ktmp > K:
        break
    kcnt += 1
print(kcnt)

Submission status: Wrong Answer

Solution code:
from bisect import *
from itertools import accumulate
n, m, k = map(int, input().split())
a = [0]+list(map(int, input().split()))
b = [0]+list(map(int, input().split()))
a = list(accumulate(a))
b = list(accumulate(b))
ans = 0
for i in range(n+1):
    ind = bisect_right(b, k-a[i])
    ans = max(ans, ind+i-1)

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    from bisect import bisect_right

    N,M,K=list(map(int,sys.stdin.readline().split()))
    A=list(map(int,sys.stdin.readline().split()))
    B=list(map(int,sys.stdin.readline().split()))

    AS=[0]*N
    BS=[0]*M
    for i,a in enumerate(A):
        if i:
            AS[i]=AS[i-1]+a
        else:
            AS[i]=a

    for i,b in enumerate(B):
        if i:
            BS[i]=BS[i-1]+b
        else:
            BS[i]=b
    mx=0
    for i,sa in enumerate(AS):
        if K-sa>=0:
            p=bisect_right(BS,K-sa)
            mx=max(mx,i+p+1)

    print(mx)


main()

Submission status: Wrong Answer

Solution code:
from collections import deque
n, m, k = map(int, input().split())
arr1 = deque(list(map(int, input().split())))
arr2 = deque(list(map(int, input().split())))

c = 0
t = 0
while len(arr1) > 0 or len(arr2) > 0:
    if len(arr1) == 0:
        s = arr2.popleft()
        t += s
    elif len(arr2) == 0:
        f = arr1.popleft()
        t += f
    elif arr1[0] <= arr2[0]:
        f = arr1.popleft()
        t += f
    elif arr2[0] < arr1[0]:
        s = arr2.popleft()
        t += s
    if t > k:
        break
    c += 1
print(c)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
i=0
j=0
a.append(10000000000)
b.append(10000000000)
while True:
    if i==n and j==m:
        break
    elif a[i]<=b[j] or j==m:
        if k-a[i]<0:
            break
        k-=a[i]
        ans+=1
        i+=1
    elif a[i]>b[j] or i==n:
        if k-b[j]<0:
            break
        k-=b[j]
        ans+=1
        j+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import math
import collections
from collections import deque 
from functools import reduce

# input = sys.stdin.readline

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ab = a + b
ab.sort()
cnt = 0
tt = 0
for ti in ab:
    if (tt + ti > k):
        break
    cnt += 1
    tt += ti
print(cnt)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, M, K = LI()
    A = LI()
    B = LI()
    t = 0
    cnt = 0
    ai = 0
    bi = 0
    end = False
    while t < K and ai < N and bi < M:
        if t + min(A[ai], B[bi]) > K:
            end = True
            break

        if A[ai] < B[bi]:
            t += A[ai]
            ai += 1
        else:
            t += B[bi]
            bi += 1
        cnt += 1

    if end:
        print(cnt)
        return

    if ai == N and bi < M:
        while t < K and bi < M:
            if t + B[bi] > K:
                print(cnt)
                return
            t += B[bi]
            bi += 1
            cnt += 1
        print(cnt)
        return

    if ai < N and bi == M:
        while t < K and ai < N:
            if t + A[ai] > K:
                print(cnt)
                return

            t += A[ai]
            ai += 1
            cnt += 1
        print(cnt)
        return

    print(cnt)



main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
input=lambda : stdin.readline().strip()
from math import ceil,sqrt,factorial,gcd
from collections import deque
# s=input()
# t=input()
# count=0
# for i in range(len(s)):
# 	if s[i]!=t[i]:
# 		count+=1
# print(count)
n,m,k=map(int,input().split())
l=list(map(int,input().split()))
z=list(map(int,input().split()))
l.reverse()
z.reverse()
count=0
while k>0:
	if len(l)>0 and len(z)>0:
		x=l.pop()
		y=z.pop()
		if x<=y and x<=k:
			k-=x
			count+=1
			z.append(y)
		elif y<x and y<=k:
			k-=y
			count+=1
			l.append(x)
		else:
			break
	elif len(l)>0:
		x=l.pop()
		if x<=k:
			k-=x
			count+=1
		else:
			break
	elif len(z)>0:
		y=z.pop()
		if y<=k:
			k-=y
			count+=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()))

i, j = 0, 0
a, b = 0, 0
time = 0
ans = 0
while time <= K:
  if (a == 1) and (b == 1):
    print(ans)
    quit()
  elif a == 1:
    next_book = B[j]
    j += 1
  elif b == 1:
    next_book = A[i]
    i += 1
  else:
    #print(i, j)
    next_book = min(A[i], B[j])
    if next_book == A[i]:
      i += 1
    else:
      j += 1
  
  if i == N:
    a = 1
  if j == M:
    b = 1
    
  if time + next_book <= K:
    ans += 1
    time += next_book
  else:
    print(ans)
    quit()
  #print(i, j, time)
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
time = 0
count = 0
while time < K:
    if not A and B:
        time += B[0]
        B.pop(0)
        count += 1
    elif not B and A:
        time += A[0]
        A.pop(0)
        count += 1
    else:
        if A[0] < B[0] and time + A[0] <= K:
            time += A[0]
            A.pop(0)
            count += 1
        elif time + B[0] <= K:
            time += B[0]
            B.pop(0)
            count += 1
        else:
            break
print(count)

Submission status: Wrong Answer

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

t = 0
ans = 0
for i in range(10):
    #print(t)
    if t >= K or (A and t + A[-1] > K and B and t + B[-1] > K):
        break
    
    if A and B:
        if A[-1] <= B[-1]:
            if t + A[-1] <= K:
                t += A.pop()
                ans += 1
        else:
            if t + B[-1] <= K:
                t += B.pop()
                ans += 1
    elif A:
        if t + A[-1] <= K:
            t += A.pop()
            ans += 1
    elif B:
        if t + B[-1] <= K:
            t += B.pop()
            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()))
ans = 0
while (K > 0):
  if len(A) == 0:
    K-= B[0]
    B = B[1:]
    ans += 1
    continue
  if len(B) == 0:
    K-= A[0]
    A = A[1:]
    ans += 1
    continue
  if A[0] >= B[0] and K - B[0] >= 0:
    ans += 1
    K -= B[0]
    B = B[1:]
    continue
  elif B[0] >= A[0] and K - A[0] >= 0:
    ans += 1
    K -= A[0]
    A = A[1:]
    continue
  else:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)

def main():
    N,M,K = [int(i) for i in input().strip().split()]
    A_l = list(reversed([int(i) for i in input().strip().split()]))
    B_l = list(reversed([int(i) for i in input().strip().split()]))

    top_a = A_l.pop()
    top_b = B_l.pop()

    ans = 0

    while top_a <= K or top_b <= K:
        if top_a < top_b:
            K -= top_a
            if len(A_l) > 0:
                top_a = A_l.pop()
            else:
                top_a = float("inf")
            ans += 1
        else:
            K -= top_b
            if len(B_l) > 0:
                top_b = B_l.pop()
            else:
                top_b = float("inf")
            ans += 1

    return ans

if __name__ == "__main__":
    print(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()))
aInd = 0
bInd = 0
cnt = 0
while True:
    if aInd<N and bInd<M:
        if A[aInd]<B[bInd]:
            time = A[aInd]
            aInd += 1
        else:
            time = B[bInd]
            bInd += 1
        K -= time
        if K >= 0:
            cnt += 1
        else:
            break
    elif aInd == N and bInd == M:
        break
    elif aInd == N:
        time = B[bInd]
        bInd += 1
        K -= time
        if K >= 0:
            cnt += 1
        else:
            break
    else:
        time = A[aInd]
        aInd += 1
        K -= time
        if K >= 0:
            cnt += 1
        else:
            break
print(cnt)

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

A.append(10000000000000)
B.append(10000000000000)

time = 0
a_num = 0
b_num = 0
for i in range(N+M):
    if A[a_num] <B[b_num]:
        time += A[a_num]
        a_num+=1
    else:
        time += B[b_num]
        b_num+=1
    
    if time >= K:
        break
else:
    print(a_num+b_num)
    sys.exit()
print(a_num+b_num-1)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
A.append(10**9+1)
B.append(10**9+1)
a = 0
b = 0
ans = 0
t = 0
while t < K :
    if A[a] <= B[b]:
        if t+A[a] <= K:
            ans += 1
            t += A[a]
            a += 1
        else:
            break
    else:
        if t+B[b] <= K:
            ans += 1
            t += B[b]
            b += 1
        else:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,m,k=nm()
a=nl()
b=nl()

sm=0

ai=0
bi=0

cnt=0
for i in range(n+m):
  bk = 0
  if ai==n:
    bk = b[bi]
    bi+=1
  elif bi==m:
    bk = a[ai]
    ai+=1
  else:
    bk = min(a[ai],b[bi])
    if bk == a[ai]:
      ai+=1
    else:
      bi+=1

  if sm+bk > k:
    break
  sm+=bk
  cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import *
import sys
from bisect import *
input=sys.stdin.readline
from math import *
t=1
while(t):
    t-=1
    n,m,k=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    i,j=0,0
    r=0
    while(1):
        ff=0
        if(i<n and j<m):
            if(a[i]<=b[j] and k>=a[i]):
                r+=1
                ff=1
                k-=a[i]
                i+=1
            elif(k>=b[j]):
                j+=1
                ff=1
                r+=1
                k-=b[j-1]
        elif(i>=n and j<m):
            if(k>=b[j]):
                r+=1
                k-=b[j]
                j+=1
                ff=1
        elif(j>=m and i<n):
            if(k>=a[i]):
                r+=1
                k-=a[i]
                i+=1
                ff=1
        else:
            break
        #print(k,ff,i,j)
        if(ff==0):
            break
    print(r)

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 and (len(A) > 0 or len(B)>0):
  if len(A) == 0 and len(B) == 0:
    break
  if len(A) == 0:
    t += B.popleft()
    if t <= K:
      ans += 1
      continue
    else:
      break
  elif len(B) == 0:
    t += A.popleft()
    if t <= K:
      ans += 1
      continue
    else:
      break

  if A[0] <= B[0]:
    t += A.popleft()
    if t <= K:
      ans += 1
    else:
      break
  else:
    t += B.popleft()
    if t <= K:
      ans += 1
    else:
      break
  
print(ans)

Submission status: Wrong Answer

Solution code:
# itne me hi thakk gaye?
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = 0
ans = 0
p1, p2 = 0, 0
while(p1 < n and p2 < m):
    if (a[p1] < b[p2]):
        if (s + a[p1] <= k):
            s += a[p1]
            p1 += 1
            ans += 1
        elif (s + b[p2] <= k):
            s += b[p2]
            p2 += 1
            ans += 1
        else:
            break
    else:
        if (s + b[p2] <= k):
            s += b[p2]
            p2 += 1
            ans += 1
        elif (s + a[p1] <= k):
            s += a[p1]
            p1 += 1
            ans += 1
        else:
            break
while(p1 < n):
    if(s + a[p1] <= k):
        s += a[p1]
        p1 += 1
        ans += 1
    else:
        break
while(p2 < m):
    if(s + b[p2] <= k):
        s += b[p2]
        p2 += 1
        ans += 1
    else:
        break 
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M , W = MAP()
A = LIST()
B = LIST()
A = deque(A)
B = deque(B)

# C = A + B
cnt = 0
while W > 0:
    if len(A) != 0 and len(B) != 0:
        a = A[0]
        b = B[0]
        if a <= b:
            W -= a
            A.popleft()
        else:
            W -= b
            B.popleft()
    elif len(A) != 0:
        # a = INF
        a = A.popleft()
        W -= a
    elif len(B) != 0:
        # a = INF
        b = B.popleft()
        W -= b
    # print(W)
    if W >= 0:
        cnt += 1


print(cnt)



# 3 4 240
# 60 90 120
# 80 150 80 150
# 出力例 1

Submission status: Wrong Answer

Solution code:
def INT():
    return int(input())

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

def LI():
    return list(map(int, input().split()))

from collections import deque

N, M, K = MI()
A = deque(LI())
B = deque(LI())
ans = 0
time = 0

while True:
    a, b = 10**10, 10**10
    if len(A) != 0:
        a = A.popleft()
    if len(B) != 0:
        b = B.popleft()
    
    tmp = min(a, b)
    time += tmp
    
    if tmp == a:
        B.appendleft(b)
    else:
        A.appendleft(a)
    
    if time > K:
        break
    
    ans += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
import queue
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
a = 0
b = 0
time = 0
while(time < K and a + b < N+M):
    m = 0
    if a < N and b < M:
        if A[a] < B[b]:
            m = A[a]
            a += 1
        else:
            m = B[b]
            b += 1
    elif a < N and b == M:
        m = A[a]
        a += 1
    elif a == N and b < M:
        m = B[b]
        b += 1
    else:
        break

    time += m
    # print(time, K)
    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()))
A.sort(reverse=True)
B.sort(reverse=True)
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().strip().split())
A = list(map(int, input().strip().split()))[::-1]
B = list(map(int, input().strip().split()))[::-1]
time=0
ans=0
while A or B:
    if not B or A and A[-1]<B[-1]:
        time+=A.pop()
    else:
        time+=B.pop()
    if time>k:
        break
    ans+=1

print(ans)

Submission status: Wrong Answer

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

A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

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):
    ai += 1
    t += 1
    if t <= k:
      ans += 1
  else:
    bi += 1
    t += 1
    if t <= 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()))
C=0
D=0
if A[C]<=B[D]:
  C+=1
else:
  D+=1
print(C+D+2)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right

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

x = [0] * (N + 1)
for i in range(N):
    x[i + 1] = x[i] + A[i]
    
y = [0] * (M + 1)
for i in range(M):
    y[i + 1] = y[i] + B[i]

ans = 0
for i in range(N + 1):
    res = K - x[i]
    if res <= 0:
        continue
        
    j = bisect_right(y, res)
    ans = max(ans, i + j - 1)
print(ans)

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()))
total=0
ans=0
while True:
  if len(a)==0 and len(b)==0:
    break
  elif len(b)==0:
    if total+a[0]>k:
      break
    else:
      total+=a[0]
      a.popleft()
      ans+=1
  elif len(a)==0:
    if total+b[0]>k:
      break
    else:
      total+=b[0]
      b.popleft()
      ans+=1
  else:
    if total+min(a[0],b[0])>k:
      break
    else:
      total+=min(a[0],b[0])
      if a[0]>b[0]:
        b.popleft()
      else:
        a.popleft()
      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()))
c = a + b
c = sorted(c)
o = n + m

t = 0
for i in range(o):
    t += c[i]
    #print(t)
    if t == k:
        print(i+1)
        break
    elif t > k:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
n,m,k=[int(_) for _ in input().split()]
A=[int(_) for _ in input().split()]
B=[int(_) for _ in input().split()]
jikan=0
yomi=0
while (A or B):
    if A and B:
        if A[0]<B[0]:
            jikan+=A.pop(0)
        else:
            jikan+=B.pop(0)
    elif A:
        jikan+=A.pop(0)
    else:
        jikan+=B.pop(0)
    
    if jikan<=k:
        yomi+=1
print(yomi)

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,0
ai,bj=0,0
while True:
    if len(a)<=i:
        ai=10**9+7
    else:
        ai=a[i]
    if len(b)<=j:
        bj=10**9+7
    else:
        bj=b[j]
    if k<ai and k<bj:
        break
    if ai<bj:
        k-=ai
        i+=1
    else:
        k-=bj
        j+=1
    # print(i,j,k)
print(i+j)

Submission status: Wrong Answer

Solution code:
def main():
    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()]

    a.append(10**9+1)
    b.append(10**9+1)
    cnt_a = 0
    cnt_b = 0
    cumsum = 0

    while cumsum < k:
        if a[cnt_a] > b[cnt_b]:
            cumsum += b[cnt_b]
            if cumsum > k:
                break
            cnt_b += 1
        else:
            cumsum += a[cnt_a]
            if cumsum > k:
                break
            cnt_a += 1
    print(cnt_a + cnt_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
cnt = 0
while time <= K:
  if len(A) == 0 and len(B) == 0:
    break
  if len(A) == 0:
    tmp = B.pop(0)
  elif len(B) == 0:
    tmp = A.pop(0)
  elif A[0]<B[0]:
    tmp = A.pop(0)
  else:
    tmp = B.pop(0)
  time += tmp
  if time > K:
    break
  cnt += 1
 # print(time,A,B)
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N, M, K = rl()
A = rl()
B = rl()

A.reverse()
B.reverse()

C = []
while len(A)>0 and len(B)>0:
	if A[-1] > B[-1]:
		C.append(B.pop())
	else:
		C.append(A.pop())
while len(A) > 0:
	C.append(A.pop())
while len(B) > 0:
	C.append(B.pop())

ans = 0
for c in C:
	K -= c
	if K >= 0:
		ans += 1
	else:
		break
print(ans)

Submission status: Wrong Answer

Solution code:
#                          JAI SHREE RAM

import math; from collections import *
import sys; from functools import reduce

def get_ints(): return map(int, input().strip().split())
def get_list(): return list(get_ints())
def getlistofstring(): return list(input().strip().split())
def printxsp(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")

UGLYMOD = int(1e9)+7; SEXYMOD = 998244353; MAXN = int(1e5)

n, m, k = get_ints()
a = get_list()
b = get_list()
ans = i = j = 0
while k > 0 and (i < n and j < m):
    if a[i] < b[j]:
        if k - a[i] >= 0:
            ans += 1
            k -= a[i]
            i += 1
        else: break
    else:
        if k - b[j] >= 0:
            ans += 1
            k -= b[j]
            j += 1
        else: break
if k > 0:
    if j != m:
        while k > 0 and j < m:
            if k - b[j] >= 0:
                ans += 1
                k -= b[j]
                j += 1
            else: break
    if i != m:
        while k > 0 and i < n:
            if k - a[i] >= 0:
                ans += 1
                k -= a[i]
                i += 1
            else: break
print(ans)





# sys.setrecursionlimit(10**6)
# sys.stdin=open("input.txt","r");sys.stdout=open("output.txt","w")

# for _testcases_ in range(int(input())):

'''
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
THE LOGIC AND APPROACH IS MINE @luctivud ( UDIT GUPTA )
Link may be copy-pasted here if it's taken from other source.
DO NOT PLAGIARISE.
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
'''