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
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    N, M, K = MI()
    A = deque(LI())
    B = deque(LI())

    ans = 0
    sm = 0
    for _ in range(N+M):
        if A and B:
            a = A.popleft()
            b = B.popleft()
            if a < b:
                if a + sm <= K:
                    sm = sm + a
                    ans += 1
                    B.appendleft(b)
                else:
                    break
            else:
                if b + sm <= K:
                    sm = sm + b
                    ans += 1
                    A.appendleft(a)
                else:
                    break
        elif A:
            a = A.popleft()
            if sm + a <= K:
                sm = sm + a
                ans += 1
            else:
                break
        elif B:
            b = B.popleft()
            if sm + b <= K:
                sm = sm + b
                ans += 1
        else:
            break
    print(ans)





if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n, m, k = nm()
    a = nl()
    a = a[::-1]
    b = nl()
    b = b[::-1]

    ans = 0
    i = 0
    flag = True
    while flag:
        flag = False
        if a == []:
            a.append(10**9)
        elif b == []:
            b.append(10**9)
        if a[-1] <= b[-1] and a[-1] <= k:
            k -= a.pop()
            ans += 1
            flag = True
        elif a[-1] > b[-1] and b[-1] <= k:
            k -= b.pop()
            ans += 1
            flag = True

    print(ans)
   

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N,M,K= [int(x) for x in sys.stdin.readline().split()]

A = [int(x) for x in sys.stdin.readline().split()]

B = [int(x) for x in sys.stdin.readline().split()]

a = sorted(A + B)

# print(a)

time = 0
i = 0
ans = 0
while True:
    # print(i)
    if i == len(a):
        break
    if time + a[i] <= K:
        time += a[i]
        i += 1
        continue
    else:
        break
print(i)

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

Submission status: Wrong Answer

Solution code:
n,m,k=(int(i) for i in input().split())
l1=[int(i) for i in input().split()]
l2=[int(i) for i in input().split()]
c=0
minu=0
i=0
j=0
n1=len(l1)
n2=len(l2)
while(minu<=k):
    if(i<n1 and j<n2):
        k1=min(l1[i],l2[j])
        if(minu+k1<=k):
            minu+=k1
            c+=1
            if(k1==l1[i]):
                i+=1
            else:
                j+=1
        else:
            break
    elif(i<n1):
        if(minu+l1[i]<=k):
            minu+=l1[i]
            c+=1
            i+=1
        else:
            break
    elif(j<n2):
        if(minu+l2[j]<=k):
            minu+=l2[j]
            c+=1
            j+=1
        else:
            break
    else:
        break
print(c)

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:
        sub += a
        if sub > k: break
        cnt += 1
        B.append(b)
    else:
        sub += b
        if sub > k: break
        cnt += 1
        A.append(a)
print(cnt)

Submission status: Wrong Answer

Solution code:
N,M,L = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
cnt = 0
while True:
    if L < 0:
        cnt -= 1
        break
    else:
        if A != [] and B != []:
            tmp = min(A[0],B[0])
            L -= tmp
            cnt +=1
            if tmp == A[0]:
                A = A[1:]
            else:
                B = B[1:]
        elif A==[] and B==[]:
            break
        elif A == []:
            tmp = B[0]
            L -= tmp
            cnt += 1
            B = B[1:]
        elif B == []:
            tmp = A[0]
            L -= tmp
            cnt +=1
            A = A[1:]
        else:
            break
print(cnt)

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,m,k = readInts()
A = readInts()
B = readInts()
import heapq
heapq.heapify(A)
heapq.heapify(B)
ks = 0
cnt = 0
while ks < k:
    if len(A) == 0 and len(B) == 0:
        break
    if len(A) != 0 and len(B) != 0:
        a = heapq.heappop(A)
        b = heapq.heappop(B)
        if a < b:
            ks += a
            if ks > k:
                break
            cnt += 1
            heapq.heappush(B,b)
        else:
            ks += b
            if ks > k:
                break
            cnt += 1
            heapq.heappush(A,a)
    elif len(A) != 0 and len(B) == 0:
        a = heapq.heappop(A)
        ks += a
        if ks > k:
            break
        cnt += 1
    elif len(B) != 0 and len(A) == 0:
        b = heapq.heappop(B)
        ks += b
        if ks > k:
            break
        cnt += 1
    #print(ks)
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()))
t=0
ans=0
aq=deque(a)
bq=deque(b)
aq.append(k*100)
bq.append(k*100)
while t<k and len(aq)!=0 and len(bq)!=0:
    ans+=1
    if aq[0]<=bq[0]:
        t+=aq.popleft()
    else:
        t+=bq.popleft()
if t>k:
    print(ans-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
temp=0
an,bn=0,0
ans=0
while temp<=k:
    if an==n and bn==m: break
    if an>=n:
        temp+=b[bn]
        if temp>k: break
        bn+=1
    elif bn>=m:
        temp+=a[an]
        if temp>k: break
        an+=1
    else:
        if a[an]<b[bn]:
            temp+=a[an]
            if temp>k: break
            an+=1
        else:
            temp+=b[bn]
            if temp>k: break
            bn+=1
    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()))
alen=0
blen=0
minute=0
ans=0
while(minute<=k):
    if(alen==n and blen==m):
        break
    elif(alen==n and blen<m):
        minute+=b[blen]
        ans+=1
        blen+=1
    elif(alen<n and blen==m):
        minute+=a[alen]
        ans+=1
        alen+=1
    else:
        if(a[alen]<b[blen]):
            minute+=a[alen]
            alen+=1
        else:
            minute+=b[blen]
            blen+=1
        ans+=1
if(minute<=k):
    print(ans)
else:
    print(ans-1)

Submission status: Wrong Answer

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

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

ans = 0
ans0 = 0
ans1 = 0
for i in range(n):
    if A[i] + ans0 <= k:
        ans0 += A[i]
        ans1 += 1
    else:
        break
ind = ans1-1

jnd = 0
for i in range(m):
    if B[i] + ans0 <= k:
        ans0 += B[i]
        ans1 += 1
        jnd += 1
    else:
        break


ans = ans1
# print(ans)

for i in range(ind, -1, -1):
    ans1 -= 1
    ans0 -= ind
    while jnd < m and ans0 + B[jnd] <= k:
        ans0 += jnd
        jnd += 1
        ans1 += 1
    ans = max(ans, ans1)
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect
from itertools import accumulate
from sys import stdin


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

    book = list(accumulate(sorted(A + B)))
    ans = bisect(book, K)
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")



def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

n,m,k = Ri()

a = Ri()
b = Ri()

i,j = 0,0
ans = 0
flag = True
while i < n and j < m:
    if a[i] < b[j]:
        if k >= a[i] :
            ans+=1
            k-=a[i]
            i+=1
        else:
            # print("fs")
            flag = False
            break
    else:
        if k >= b[j]:
            ans+=1
            k-=b[j]
            j+=1
        else:
            # print("fs")
            flag = False
            break
if not flag : 
    # print("fsf")
    print(ans)
else:
    # print("fs")
    flag = True
    while  i < n:
        if a[i] <= k:
            ans+=1
            k-=a[i]
            i+=1
        else:
            flag = False
            break

    while  j < m:
        if b[j] <= k:
            ans+=1
            k-=b[j]
            j+=1
        else:
            flag = False
            break

    print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    INF = 10**18
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    a.append(INF)
    b.append(INF)
    ap = 0
    bp = 0

    cnt = 0
    now = 0
    while now <= k:
        if a[ap] <= b[bp]:
            now += a[ap]
            ap += 1
        else:
            now += b[bp]
            bp += 1
        if now <= k:
            cnt +=1
    print(cnt)

main()

Submission status: Wrong Answer

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

ia = 0
ib = 0
count = 0
bCount = 0
while count <= k:
    bA = -1
    bB = -1
    if ia < len(listA):
        bA = listA[ia]
    if ib < len(listB):
        bB = listB[ib]
    if bA != -1 and bB != -1:
        if bA < bB and count+bA <= k:
            bCount+=1
            count+=bA
            ia+=1
        elif bA >= bB and count+bB <= k:
            bCount += 1
            count += bB
            ib += 1
        else:
            break
    elif bA != -1:
        if count+bA <= k:
            bCount += 1
            count += bA
            ia += 1
        else:
            break
    elif bB != -1:
        if count+bB <= k:
            bCount += 1
            count += bB
            ib += 1
        else:
            break
    else:
        break
print(bCount)

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.extend(b)
a.sort()
cumsum = list(itertools.accumulate(a))
ans = 0
for i in cumsum:
    if i > k:
        break
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

As.append(np.inf)
Bs.append(np.inf)

count = 0
while K >= min(As[0], Bs[0]):
    if As[0] <= Bs[0]:
        t = As.pop(0)
    else:
        t = Bs.pop(0)
    K -= t
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import sys 
input = lambda:sys.stdin.readline().strip()
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a = a[::-1]
b = b[::-1]
ans = 0
while (len(a) or len(b)):
    if len(a) and len(b):
        if a[-1]<b[-1]:
            if a[-1]<=k:
                v = a.pop()
                k-=v 
                ans+=1
            else:
                break
        else:
            if b[-1]<=k:
                v = b.pop()
                k-=v 
                ans+=1
            else:
                break 
    elif len(a):
        if a[-1]<=k:
            v = a.pop()
            k-=v 
            ans+=1
        else:
            break
    else:
        if b[-1]<=k:
            v = b.pop()
            k-=v 
            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()))
C = A+B
C.sort()
ans = 0
for c in C:
  if c <= k:
    ans += 1
    k -= c
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 = sorted(a+b)
ans = 0
tmp = 0
for i in c:
  tmp += i
  if(tmp > k):print(ans);exit()
  ans+=1
else:print(ans)

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()))
    ai, bi = 0, 0
    time = 0
    ans = 0
    while time <= K:
        if ai == N and bi == M:
            print(ans)
            return
        elif ai == N and bi < M:
            time += B[bi]
            bi += 1
            ans += 1
        elif bi == M and ai < N:
            time += A[ai]
            ai += 1
            ans += 1
        else:
            if B[bi] >= A[ai]:
                time += A[ai]
                ai += 1
            else:
                time += B[bi]
                bi += 1
            ans += 1
    print(ans-1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
i=j=0
cnt=0
while i<n or j<m:
    if cnt>k:break
    if j>=m:cnt+=s[i];i+=1;
    elif i>=n:cnt+=t[j];j+=1
    elif s[i]<t[j]:cnt+=s[i];i+=1;
    else:cnt+=t[j];j+=1
if i==n and j==m:print(i+j)
else:print(i+j-1)

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]
for i in range(n+m):
    if len(a)!=0 and len(b)!=0:
        c=min(a[-1],b[-1])
        f=1 if c==b[-1] else 0
    elif len(a)!=0:
        c=a[-1]
        f=0
    elif len(b)!=0:
        c=b[-1]
        f=1
    else:
        break
    if k-c<0:
        print(i)
        exit()
    else:
        k-=c
        b.pop() if f else a.pop()
print(n+m)

Submission status: Wrong Answer

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

a.append(10**10)
b.append(10**10)

i,j,ans=0,0,0
while k>=0:
    if a[i]>b[j]:
        k-=b[j]
        j+=1
    else:
        k-=a[i]
        i+=1
    ans+=1

print(ans-1)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy
def main():
    N, M, K = map(int, input().split())
    MAX = 10 ** 9 + 7
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    A.append(MAX)
    B.append(MAX)
    ans = 0
    a = 0
    b = 0
    now = 0
    while True:
        if A[a] < B[b]:
            if A[a] + now <= K:
                ans += 1
                now += A[a]
                a += 1
            else:
                break
        else:
            if B[b] + now <= K:
                ans += 1
                now += B[b]
                b += 1
            else:
                break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque

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

a = deque(A)
b = deque(B)

ans = 0
time = 0

while True:
    if time > K:
        break
    if len(a) == 0 and len(b) == 0:
        break

    if len(a) == 0:
        if b[0] > K - time:
            break
        time += b[0]
        b.popleft()
    elif len(b) == 0:
        if a[0] > K - time:
            break
        time += a[0]
        a.popleft()
    elif a[0] < b[0]:
        if a[0] > K - time:
            break
        time += a[0]
        a.popleft()
    else:
        if b[0] > K - time:
            break
        time += b[0]
        b.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()))

A.extend(B)
A.sort()
ans = 0
time = 0
for a in A:
  if time + a > k:
    break
  ans += 1
  time += a
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit
#input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 18

#N = int(input())
#S = input()
N, M, K = map(int, input().split())
#A = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ia, ib = 0, 0
la, lb = len(A), len(B)

answer = 0
sum_time = 0
while ia + ib < la + lb:
    if ia == la:
        sum_time += B[ib]
        ib += 1
    elif ib == lb:
        sum_time += A[ia]
        ia += 1
    else:
        if A[ia] <= B[ib]:
            sum_time += A[ia]
            ia += 1
        else:
            sum_time += B[ib]
            ib += 1
    if sum_time > K:
        print(answer)
        exit()
    answer += 1
    
print(answer)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import deque
input = stdin.readline

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)

ans = 0
time = 0

while A or B:
    if A:
        a = A.popleft()
    else:
        a = 10 ** 9

    if B:
        b = B.popleft()
    else:
        b = 10 ** 9

    if K - time < a and K - time < b:
        break

    if a < b:
        time += a
        ans += 1
        B.appendleft(b)
    else:
        time += b
        ans += 1
        A.appendleft(a)


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()]
a.append(int(1e10))
b.append(int(1e10))

books = 0
i = 0
j = 0
while True:
    if min(a[i], b[j]) > k: 
        break
    if a[i] <= b[j]:
        k -= a[i]
        books += 1
        i += 1
    else:
        k -= b[j]
        books += 1
        j += 1
print(books)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
# a = deque()
# b = deque()
input = lambda: sys.stdin.readline().rstrip()
n, m, k = map(int, input().split())

a = deque(list(map(int, input().split())))
b = deque(list(map(int, input().split())))
now = 0
# print(a,b)
ans = 0
while (1):
    if len(a) == 0 and len(b) == 0:
        break
    elif len(a) == 0:
        check = b.popleft()
    elif len(b) == 0:
        check = a.popleft()
    else:
        if a[0] <= b[0]:
            check = a.popleft()
        else:
            check = b.popleft()

    if now + check > k:
        break
    else:
        now += check
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(1, n):
    a[i] += a[i - 1]
for i in range(1, m):
    b[i] += b[i - 1]
ans = 0
for i in range(n):
    x = k - a[i]
    if not x < 0:
        j = bisect.bisect_right(b, x)
        ans = max(ans, i + j + 1)
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math
from bisect import bisect,bisect_right,bisect_left

def get_int():
    return int(stdin.readline().strip())


def get_tuple():
    return map(int, stdin.readline().split())


def get_list():
    return list(map(int, stdin.readline().split()))

n,m,k = get_tuple()
ls1 = get_list()
ls2 = get_list()
i,j,c = 0,0,0
while i<n and j<m:
    if k<ls1[i] and k<ls2[j]:
        break
    c += 1
    if ls1[i]<=ls2[j]:
        k -= ls1[i]
        i += 1
    else:
        k -= ls2[j]
        j += 1
while  i<n and k>=ls1[i]:
    k -= ls1[i]
    c += 1
    i += 1

while j<m and k>=ls2[j] :
    k -= ls2[j]
    c += 1
    j += 1
print(c)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N,M,K= [int(x) for x in sys.stdin.readline().split()]

A = [int(x) for x in sys.stdin.readline().split()]

B = [int(x) for x in sys.stdin.readline().split()]

a = sorted(A + B)

print(a)

time = 0
i = 0
ans = 0
while True:
    # print(i)
    if i == len(a):
        break
    if time + a[i] <= K:
        time += a[i]
        i += 1
        continue
    else:
        break
print(i)

Submission status: Wrong Answer

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


ans = 0
c = 0
while ans <= X:
  if A[0] > B[0]:
    b = B.pop(0)
    if ans+b > X:
      break
    ans += b
    c += 1
  else:
    a = A.pop(0)
    if ans+a > X:
      break
    ans += a
    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()))
x = 0
satsu = 0
ind1, ind2 = 0,0
while True:
    if ind1 < n and ind2 < m:
        if a[ind1] < b[ind2]:
            if x + a[ind1] <= k:
                x += a[ind1]
                ind1 += 1
                satsu += 1
            else:
                break
        else:
            if x + b[ind2] <= k:
                x += b[ind2]
                ind2 += 1
                satsu += 1
            else:
                break
    elif ind1 < n:
        if x + a[ind1] <= k:
            x += a[ind1]
            ind1 += 1
            satsu += 1
        else:
            break
    elif ind2 < m:
        if x + b[ind2] <= k:
            x += b[ind2]
            ind2 += 1
            satsu += 1
        else:
            break
    else:
        break
print(satsu)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

a = deque(a)
b = deque(b)

aa = a.popleft()
bb = b.popleft()

ans = 0
time = 0
for i in range(n+m):
    if time + min(aa, bb) > k:
        break
    if aa <= bb:
        time += aa
        if len(a) == 0:
            aa = 10**9+1
        else:
            aa = a.popleft()
    else:
        time += bb
        if len(b) == 0:
            bb = 10**9+1
        else:
            bb = b.popleft()
    ans += 1
    #print(ans, aa, bb)

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.extend(b)
a.sort()
ans = 0

for i in range(n+m):
    if a[i] <= k:
        ans += 1
        k -= a[i]
    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()))

i, j, ans = 0, 0, 0
while K > 0:
    if i == N and j == M:
        break
    elif i == N:
        K -= B[j]
        j += 1
        ans += 1
    elif j == M:
        K -= A[i]
        i += 1
        ans += 1
    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, = map(int, input().split())
*B, = map(int, input().split())
a, b = 0, 0
while K > 0:
    c = "None"
    if a < N and b < M:
        if A[a] < B[b]:
            c = "A"
        else:
            c = "B"
    elif a < N:
        c = "A"
    elif b < M:
        c = "B"
    else:
        break

    if c == "A":
        K -= A[a]
        if K < 0:
            break
        a += 1
    else:
        K -= B[b]
        if K < 0:
            break
        b += 1
print(a+b)

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:
import sys
# from math import sqrt, gcd, ceil, log
from bisect import bisect_left
from collections import defaultdict, Counter
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

# sys.setrecursionlimit(10**6)



def solve():
	a, b, k = read(); a_ = read(); b_ = read()
	ans = 0; i = 0; j = 0; t = 0
	while t < k and i<a and  j< b:
		if a_[i] < b_[j]:t += a_[i];i += 1;
		else:t += b_[j]; j += 1
		ans += 1
	while t < k and i<a:
		t += a_[i];i += 1;ans += 1
	while t < k and j < b:
		t += b_[j]; j += 1
		ans += 1
	if t > k: ans -= 1
	print(ans)





		

if __name__ == "__main__":
	solve()