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 = (int(s) for s in input().rstrip().split())

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

i, j = (0, 0)
sum, count = (0, 0)

while sum <= K:
  if (i < N) and (j < M):
    if A[i] <= B[j]:
      sum += A[i]
      i += 1
      count += 1
    else:
      sum += B[j]
      j += 1
      count += 1
  elif i < N:
    sum += A[i]
    i += 1
    count += 1
  elif j < N:
    sum += B[j]
    j += 1
    count += 1
  else:
    count += 2
    sum = K + 1
    break
    
print(count - 1)

Submission status: Wrong Answer

Solution code:
from collections import deque

l1 = str(input()).split()

N = int(l1[0])
M = int(l1[1])
K = int(l1[2])

aq = deque([int(v) for v in str(input()).split()])
bq = deque([int(v) for v in str(input()).split()])

t = 0
count = 0
while len(aq) > 0 or len(bq) > 0:
    if len(bq) == 0:
        t += aq.popleft()
    elif len(aq) == 0:
        t += bq.popleft()
    elif aq[0] < bq[0]:
        t += aq.popleft()
    else:
        t += bq.popleft()

    if t > K:
        break

    count += 1

print(count)

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

ans = 0
r_time = 0
for i in range(N+M+1):
    if A_que and B_que:
        if A_que[0] > B_que[0]:
            r_time += B_que.popleft()
        else:
            r_time += A_que.popleft()
    elif A_que:
        r_time += A_que.popleft()
    elif B_que:
        r_time += B_que.popleft()
    else:
        break
    if r_time <= K:
        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()))
import numpy
import sys
a_x = numpy.cumsum(a)
b_x = numpy.cumsum(b)

ans = 0
a_count = [x for x in a_x if x <=k]
b_count = [x for x in b_x if x <=k]
if len(a_count)== 0 and len(b_count)==0:
    print("0")
    sys.exit()
elif len(a_count) == 0:
    print(len(b_count))
    sys.exit()
elif len(b_count) == 0:
    print(len(a_count))
    sys.exit()
for i in range(len(a_count)):
    for j in range(len(b_count)):
        if (a_count[i] + b_count[j]) <= k:
            if ans < i+j+2:
                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()))

a1=deque(A)
b1=deque(B)
honn=0
time=0
a=a1.popleft()
b=b1.popleft()
for i in range(N+M):
    if a>=b:
        time+=b
        if len(b1)>0:
            b=b1.popleft()
        else:
            b=10**10
        if time<=K:
            honn+=1
            continue
        else:
            break
    if a<b:
        time+=a
        if len(a1)>0:
            a=a1.popleft()
        else:
            a=10**10
        if time<=K:
            honn+=1
            continue
        else:
            break
    

      
print(honn)

Submission status: Wrong Answer

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
count = 0
Ain = 0
Bin = 0
check = False
if(min(A[0],B[0])>K):
    print(0)
    exit()
while K>0:
    if(Ain != N and Bin !=M): 
        if(A[Ain] < B[Bin]):
            K-=A[Ain]
            Ain += 1
        elif(A[Ain]>B[Bin]):
            K-=B[Bin]
            Bin += 1
        
    elif((Ain == N) and (Bin == M)):
        check = True
        break
    elif(Ain==N):
        K -= B[Bin]
        Bin += 1
    elif(Bin==M):
        K -= A[Ain]
        Ain += 1
if((K==0) or check):
    print(Ain+Bin)
else:
    print((Ain+Bin)-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()))
h, j = max(A), max(B)
fe = max(h,j)
c = 0
time = 0
num = N+M
while num > 0:
    if A[0] < B[0]:
        K -= A.pop(0)
    elif A[0] > B[0]:
        K -= B.pop(0)
    c += 1
    if len(A) == 0:
        A = A + [fe+1]
    if len(B) == 0:
        B = B + [fe+1]
    num -= 1
print(c)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]

time = 0
cnt = 0
while True:
  if As[0] < Bs[0]:
    if time + As[0] > K:
      break
    time+=As[0]
    del As[0]
    if As == []:
      As.append(10**10)
  else:
    if time + Bs[0] > K:
      break
    time+=Bs[0]
    del Bs[0]
    if Bs == []:
      Bs.append(10**10)
  cnt+=1
print(cnt)

Submission status: Wrong Answer

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

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, a in enumerate(A):
    time = K - a
    if time < 0:
        continue
    cnt = i + 1
    if time != 0:
        tmp = bisect(B, time)
        cnt += tmp
    ans = max(ans, cnt)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M, K = il()
    A = deque(il())
    B = deque(il())
    A.append(MAX)
    B.append(MAX)

    time, ret = 0, 0
    while True:
        if A[0] <= B[0] and time + A[0] <= K:
            time += A[0]
            ret += 1
            A.popleft()
        elif B[0] <= A[0] and time + B[0] <= K:
            time += B[0]
            ret += 1
            B.popleft()
        else:
            break
    print(ret)

if __name__ == '__main__':
    main()

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()))
AA=[0]*(N+1)
BB=[0]*(M+1)
A3=0
B3=0
high=0
for i in range(0,N):
    A3+=A[i]
    AA[i+1]=A3
for j in range(0,M):
    B3+=B[j]
    BB[j+1]=B3
for i in range(0,N+1):
    while True:
        if BB==[]:
            break
        elif AA[i]+BB[-1]>K:
            BB.pop(-1)
        else:
            break
    if high<i+len(BB)-1:
        high=i+len(BB)-1
print(high)

Submission status: Wrong Answer

Solution code:
a = input().split(" ")
N = int(a[0])
M = int(a[1])
K = int(a[2])
Ai = input().split(" ")
Bi = input().split(" ")
Ai = [int(s) for s in Ai]
Bi = [int(s) for s in Bi]
time_ = int(K)
time = 0
acount = 0
bcount = 0

for i in range(10000000000000000):
    try:
        time += Ai[i]
        if time > time_:
            time -= Ai[i]
            break
        acount += 1
    except IndexError:
        break
atime = time
time = 0
for i in range(10000000000000000):
    try:
        time += Bi[i]
        if time > time_:
            time -= Bi[i]
            break
        bcount += 1
    except IndexError:
        break
btime = time
allc = bcount
if bcount > acount:
    hic = bcount
else:
    hic = acount
# AiからBiに移す
print(acount)
print(bcount)
for i in range(acount):
    ci = i
    try:
        while time + Ai[ci] <= time_:
            time += Ai[ci]
            allc += 1
            ci += 1
        if hic < allc:
            hic = allc
    except IndexError:
        continue
    try:
        time -= Bi[bcount-1]
        bcount -= 1
        allc -= 1
    except IndexError:
        pass
    try:
        while time + Ai[ci] <= time_:
            time += Ai[ci]
            allc += 1
            ci += 1
        if hic < allc:
            hic = allc
    except IndexError:
        break

print(hic)

Submission status: Wrong Answer

Solution code:
[N,M,K]=list(map(int, input().split()))
alist=list(map(int, input().split()))
blist=list(map(int, input().split()))
clist=alist+blist
clist.sort()

time=0
ans=0

for c in clist:
    time+=c
    if time<=K:
        ans+=1


print(ans)

Submission status: Wrong Answer

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

N,M,K=map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
A_acc = list(accumulate(A))
B_acc = list(accumulate(B))
a = 0
b = 0
ans = 0
while K > 0:
    if a < N and b < M:
        if min(N,M) > max(a,b):
            if A_acc[max(a,b)] < B_acc[max(a,b)] and a < b:
                a,b = b,a
            elif A_acc[max(a,b)] > B_acc[max(a,b)] and a > b:
                a,b = b,a
        if A[a] < B[b] and A[a] <= K:
            K -= A[a]
            a += 1
        elif A[a] >= B[b] and B[b] <= K:
            K -= B[b]
            b += 1
        else:
            break
    elif a < N and A[a] <= K:
        K -= A[a]
        a += 1
    elif b < M and B[b] <= K:
        K -= B[b]
        b += 1
    else:
        break
print(a+b)

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 = 0
numb = 0
while True:
    if numa < len(A) and numb < len(B):#リストの番号をどちらも指定できる
        if A[numa] <= B[numb] and A[numa] <= K:#AがB以下かつ、Aを取り除ける
            K -= A[numa]
            numa += 1
        elif A[numa] > B[numb] and  B[numb] <= K:#AがBより大きいかつ、Bを取り除ける
            K -= B[numb]
            numb +=1
        else:#これ以上本を取り除けない
            break
    
    elif numa >= len(A) and numb < len(B):#Aだけのリストが終了
        if B[numb]<=K:
            K-= B[numb]
            numb += 1
        else:
            break
    elif numa < len(A) and numb >= len(B):#Bだけのリストが終了
        if A[numa]<=K:
            K-= A[numa]
            numa += 1
        else:
            break
    else:#リストのどちらも終了
        break
 
print(numa+numb)

Submission status: Wrong Answer

Solution code:
def Read_Count(A,B):
    Time = 0
    AC = 0
    BC = 0
    Flag = True
    while Flag:    
        if   AC==len(A) and BC==len(B):
            Flag = False
            return AC+BC
        elif AC==len(A) and BC!=len(B):
            Time += B[BC]
            BC += 1
        elif AC!=len(A) and BC==len(B):
            Time += A[AC]
            AC += 1
        else:
            if A[AC]<=B[BC]:
                Time += A[AC]
                AC += 1
            else:
                Time += B[BC]
                BC += 1
        if Time>K:
            Flag = False
            return AC+BC-1

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()]
print(max(Read_Count(A,[]),Read_Count(B,[]),Read_Count(A,B)))

Submission status: Wrong Answer

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

    a.extend(b)
    a.sort()

    count = 0
    total = 0
    i = 0
    while i < len(a):
        total += a[i]
        if total > k:
            break
        count += 1
        i += 1

    print(count)

if 'unittest' not in globals():
    resolve()

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().strip().split())
a=list(map(int,input().strip().split()))
b=list(map(int,input().strip().split()))
total=0
i=0
j=0
ans=0
while(i<n and j<m):
    if(a[i]==b[j] and a[i]+b[j]+total<=k):
        total+=(a[i]*2)
        ans+=2
        i+=1
        j+=1
    elif(a[i]==b[j] and a[i]+total<=k):
        total+=a[i]
        ans+=1
        i+=1
    elif(a[i]<b[j] and a[i]+total<=k):
        total+=a[i]
        ans+=1
        i+=1
    elif(b[j]<a[i] and b[j]+total<=k):
        total+=b[j]
        ans+=1
        j+=1
    else:
        break
while(i<n):
    if((a[i]+total)>k):
        break
    total+=a[i]
    ans+=1
    i+=1
while(j<m):
    if((b[j]+total)>k):
        break
    total+=b[j]
    ans+=1
    j+=1
print(ans)

Submission status: Wrong Answer

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

i = 0
j = 0

while i < n:
    if a[i] > k:
        break
    k -= a[i]
    i += 1
    
while j < m:
    if b[j] > k:
        break
    k -= b[j]
    j += 1

while i > 0 and j < m:
    if b[j] >= a[i - 1]:
        break
    k += a[i -1]
    i -= 1
    while j < m:
        if b[j] > k:
            break
        k -= b[j]
        j += 1
    
print(i + j)

Submission status: Wrong Answer

Solution code:
n, m, k = [int(i) for i in input().split(' ')]
a_s = [int(i) for i in input().split(' ')]
b_s = [int(i) for i in input().split(' ')]
pa = 0
pb = 0
time = 0
while True:
  do_a = False
  do_b = False
  if pa < len(a_s) and pb < len(b_s):
    if a_s[pa] < b_s[pb]:
      do_a = True
    else:
      do_b = True
  elif pa < len(a_s):  
    do_a = True
  elif pb < len(b_s):
    do_b = True
  else:
    break

  if do_a:
      time += a_s[pa]
      pa += 1
  if do_b:
      time += b_s[pb]
      pb += 1

  if time > k:
    pa -= 1
    break

print(pa + pb)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
total = 0
ac = 0
bc = 0
alen = len(a)
blen= len(b)
allbook = alen + blen
count = 0
while True:
  if k < total:
    break
  if bc < blen:
    if ac < alen and(a[ac] < b[bc]):
      total += a[ac]
      ac += 1
      count += 1
      continue
    else:
      total += b[bc]
      bc += 1
      count += 1
      continue
  if ac < alen:
    if bc < blen and (a[ac] >= b[bc]):
      total += b[bc]
      bc += 1
      count += 1
      continue
    else:
      total += a[ac]
      ac += 1
      count += 1
      continue
  break
print(count)

Submission status: Wrong Answer

Solution code:
a=[]
b=[]
lst=[]
str = input()
str1 = input()
str2 = input()
lst = str.split(' ')
n,m,k = lst
n = int(n)
m = int(m)
k = int(k)

a = str1.split(' ')
b = str2.split(' ')
i=0
j=0
count = 0
c=0
flaga=0
flagb = 0

while c<=k and flaga==0 and flagb==0:
  
  
  if i<len(a):
    
    c = c+int(a[i])
    if c<=k:
      a.pop(i)
      i = i+1
      count = count+1
    else:
      c = c-int(a[i])
      flaga=1
  #print("c:",c)
  if j<len(b):
    c = c+int(b[j])
    if c<=k:
      b.pop(j)
      j = j+1
      count = count+1
    else:
      c = c-int(b[j])
      flagb=1
   # print("c:",c)
print(count)

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()))
Ac = list(itertools.accumulate(A))
Bc = list(itertools.accumulate(B))
amax, bmax = 0, 0
for i in range(len(A)):
    if Ac[i] <= K:
        amax = i + 1
    else: break
if amax == 0:
    At = 0
else:
    At = Ac[amax - 1]
for i in range(len(B)):
    if Bc[i] + At <= K:
        bmax = i + 1
    else: break
ans = amax + bmax
if amax > 0:
    for i in range(1, amax):
        anow = amax - i
        At = Ac[anow - 1]
        for j in range(bmax-1, len(B)):
            if Bc[j] + At <= K:
                bmax = j + 1
            else: break
        ans = max(ans,anow+bmax)
if Bc[len(B)-1] <= K:
    ans = max(ans, len(B))
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K=(int(x) for x in input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))

A_i = 0
B_i = 0

A_i_sub = 0
B_i_sub = 0

next_A = A_list[A_i]
next_B = B_list[B_i]

count_read = 0

while(K >= next_A or K >= next_B):
    if(next_A <= next_B):
        K = K - next_A
        count_read += 1
        if(A_i < N-1):
            A_i += 1
            next_A = A_list[A_i]
        elif(A_i == N-1):
            next_A = 10000000000
    elif(next_B < next_A):
        count_read += 1
        if(B_i < M-1):
            B_i += 1
            next_B = B_list[B_i]
        elif(B_i == M-1):
            next_B = 10000000000

print(count_read)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=map(int,input().split())
A=list(A)
B=map(int,input().split())
B=list(B)
booka=len(A)
bookb=len(B)
time=int(0)
book=int(0)
while time<K and booka>0 and bookb>0:
    if A[0]<=B[0]:
        time += A[0]
        book += 1
        booka -= 1
        if len(A)==1:
            booka=0
            break
        A=A[1:]
    else:
        time += B[0]
        book +=1
        bookb -=1
        if len(B)==1:
            bookb=0
            break
        B=B[1:]
if time<K and booka==0:
    while time<K and bookb>0:
        time+=B[0]
        book+=1
        bookb-=1
        if bookb==1:
            bookb=0
            break
        B=B[1:]
elif time<K and bookb==0:
    while time<K and booka>0:
        time+=A[0]
        book+=1
        booka-=1
        if booka==1:
            booka=0
            break
        A=A[1:]
if time<=K:
    print(book)
else:
    print(book-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 = a[::-1]
b = b[::-1]
sum, ans = 0, 0
while(len(a)>0 and len(b)>0):
    sum+=min(a[-1],b[-1])
    if sum>k:
        break
    else:
        ans+=1
        if(a[-1] < b[-1]):
            a.pop()
        else:
            b.pop()
if(sum<k and len(a)!=0):
    for i in range(len(a)):
        sum+=a[-1]
        if sum>k:
            break
        else:
            ans+=1
            a.pop()
if(sum<k and len(b) !=0):
    for i in range(len(b)):
        sum+=b[-1]
        if sum>k:
            break
        else:
            ans+=1
            b.pop()
print(ans)

Submission status: Wrong Answer

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

time = 0
count = 0
while len(a) > 0 or len(b) > 0:
    if len(a) ==  0:
        book_b = b.popleft()
        time += book_b
        count += 1
    elif len(b) == 0:
        book_a = a.popleft()
        time += book_a
        count+= 1
    elif a[0] >= b[0]:
        book_b = b.popleft()
        time += book_b
        count += 1
    else:
        book_a = a.popleft()
        time += book_a
        count += 1
    if time > k:
        count -= 1
        break

    
print(count)

Submission status: Wrong Answer

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

a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

all_list = a_list + b_list
all_list.sort()

book_num = 0
time = 0

for book in all_list:
    time += book
    if time <= k:
        book_num += 1
    else:
        break
print(book_num)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
time_of_A = [A[0]]
for i in range(1, N):
  time_of_A.append(time_of_A[i-1]+A[i])
B = list(map(int, input().split()))
time_of_B = [B[0]]
for i in range(1, M):
  time_of_B.append(time_of_B[i-1]+B[i])

book = [0]
start = M-1
for i in range(N):
  j = start
  time = 10 ** 9 + 1
  while time > K and j >= 0:
    time = time_of_A[i] + time_of_B[j]
    j -= 1
  if time <= K:
    book.append(i+j+3)
    j +=1
    start = j
  else:
    break
print(max(book))

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_cum = []
B_cum = []

cum = 0
for a in A:
  cum += a
  A_cum.append(cum)

cum = 0
for b in B:
  cum += b
  B_cum.append(cum)

  
counter = 0
ans = 0  
for i in range(n):
    if A_cum[i]>k:
      break
    for j in range(m):
      if A_cum[i]+B_cum[j]<=k:
        ans = max(ans, i+1+j+1)
      else:
        break
            
print(ans)

Submission status: Wrong Answer

Solution code:
a, b, c = list(map(int, input().split()))
d = list(map(int, input().split()))
e = list(map(int, input().split()))
e.extend(d)
e.sort()
n = 1
    
while True:
  if sum(e[:n]) >= c:
    break
  n += 1
 
print(n)

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys

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

count_A_MAX = 0
count_B_MAX = 0
time_A = 0
time_B = 0
count_A = 0
count_B = 0
count = 0

def drill_A(time, K):
    tmp = 0
    while time <= K:
        if tmp < N and time + A[tmp] <= K:
            time+= A[tmp]
            tmp += 1
        else:
            return tmp, time

def drill_B(time, k):
    tmp = 0
    while time <= k:
        if tmp < M and time + B[tmp] <= K:
            time+= B[tmp]
            tmp += 1
        else:
            return tmp, time

count_A_MAX, time_A = drill_A(time_A, K)
count_A = count_A_MAX
for i in range(count_A + 1):
    count = max(count, count_A + drill_B(time_A, K)[0])
    count_A -= 1
    time_A -= A[count_A]
    if count == N+M:
        sys.exit()



count_B_MAX, time_B = drill_B(time_B, K)
count_B = count_B_MAX
for i in range(count_B+1):
    count = max(count, count_B + drill_A(time_B, K)[0])
    count_B -= 1
    time_B -= B[count_B]


print(count)

Submission status: Wrong Answer

Solution code:
[N,M,K] = map(int,input().split())
I = [input() for i in range(2)]
Aall = list(map(int,I[0].split()))
Ball = list(map(int,I[1].split()))
L = max([N,M])
c = 0
n = 0
m = 0
T = 0
c = 0
L = N + M
for i in range(L):
    if n < N:
        A = Aall[n] 
    else:
        A = 1000000001 
    if m < M:
        B = Ball[m] 
    else:
        B = 1000000001 
    C = min([A,B])
    T = T + C
    if T > K :
        break
    else:
        c = c + 1
        if C == A:
            n = n + 1
        elif C == B:
            m = m + 1

print(int(c))

Submission status: Wrong Answer

Solution code:
import math

a, b, k = map(int, input().split())
a_list = list(map(int, input().split()))
a_list  = a_list[::-1]


b_list = list(map(int, input().split()))
b_list  = b_list[::-1]

list_ = []
cnt=0
finish_flg = False
jikan = 0
while (len(a_list)!=0) & (len(b_list)!=0):
  a_top = a_list[-1]
  b_top = b_list[-1]

  if a_top<b_top:
    list_.append(a_top)
    a_list.pop()
  else:
    list_.append(b_top)
    b_list.pop()
  
  if sum(list_)>k:
    break
  else:
    jikan = sum(list_)
    cnt+=1
    
nokori_hon = a_list + b_list
while len(nokori_hon)!=0:
  jikan += nokori_hon.pop()
  if jikan > k:
    break
  else:
    cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split(" "))
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))
total,count = 0,0
for i in range(max(n,m)):
	if i < n and total <= k:
		if total+a[i] <= k:
			total += a[i]
			count +=1
		else:
			break
	if i < m and total <= k:
		if total+b[i] <= k:
			total += b[i]
			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()))

ans = 0
aa = 0
bb = 0
p = k

for i in range(n):
    if p - a[i] <0:
        break
    else:
        p -= a[i]
        aa += 1
ans = aa
#print(ans)

for i in range(m):
    if p - b[i] >= 0:
        p -= b[i]
        bb += 1
        if ans < aa + bb:
            ans = aa + bb
    else:
        while aa > 0:
            aa -= 1
            #print(aa)
            #print(aa)
            p += a[aa]
            if p - b[i] >= 0:
                p -= b[i]
                bb += 1
        if ans < aa + bb:
            ans = aa + bb
        if aa <= 0:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools as it
def main():
    n,m,k=map(int,input().split())
    a = list(it.accumulate(map(int, input().split())))
    b = list(it.accumulate(map(int, input().split())))
    ans = []
    for A in range(n-1,-1,-1):
        for B in range(m-1,-1,-1):
            aa = a[A]
            bb = b[B]
            #print("aa bb", aa, bb)
            if aa + bb <= k:
                #print("AB", A, B)
                ans.append(A+B+2)
                break
    #print(ans)
    print(max(ans) if len(ans) > 0 else 0)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

time = 0
book_count = 0

while time < K:
  # 本の選択
  if A and B:
    tmp_a = A[0]
    tmp_b = B[0]
    if tmp_a <= tmp_b:
      tmp = tmp_a
      A.remove(tmp_a)
    else:
      tmp = tmp_b
      B.remove(tmp_b)
  elif A and (not B):
    tmp = A[0]
    A.remove(tmp)
  elif (not A) and B:
    tmp = B[0]
    B.remove(tmp)
  else:
    break
  # 時間判定
  if time + tmp > K:
    break
  # 読む
  time += tmp
  book_count += 1

print(book_count)

Submission status: Wrong Answer

Solution code:
def main ():
    X = input()
    X = X.split(' ')
    N = int(X[0])
    M = int(X[1])
    K = int(X[2])
    print(N, M, K) 
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
  
    total = 0
    posA = 0
    posB = 0
    time = 0
    z = 0
    while z == 0:
        if posA < len(A) and A[posA] < B[posB]:
            if time + A[posA] <= K:
                time += A[posA]
                if posA != len(A) - 1:
                    posA += 1
                total += 1
            else:
                print(total)
                return
        elif  posB < len(B) and A[posA] > B[posB]:
            if time + B[posB] <= K:
                time += B[posB]
                if posB != len(B) - 1:
                    posB += 1
                total += 1
            else:
                print(total)
                return
        else:
            print(0)
            return
main ()

Submission status: Wrong Answer

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n, m, k = i_map()
    a_list = i_list()
    b_list = i_list()

    a_ruisekiwa = list(accumulate(a_list))
    b_ruisekiwa = list(accumulate(b_list))

    # print(a_ruisekiwa)
    # print(b_ruisekiwa)

    max_count = 0

    for i in range(n):
        if k < a_ruisekiwa[i]:
            break
        insert_num = k - a_ruisekiwa[i]
        insert_index = bisect_right(b_ruisekiwa, insert_num)
        max_count = max(max_count, i + insert_index +1)

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

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
mx=n
mn=m
mxl=a
mnl=b
if m>n:
    mx=m
    mn=n
    mxl=b
    mnl=a
if k<a[0] and k<b[0]:
    print(0)
else:
    sm=0
    counts=[]
    i=0
    while sm<=k and i<n:
        sm+=a[i]
        i+=1
    counts.append(i)
    sm=0
    i=0
    while sm<=k and i<m:
        sm+=b[i]
        i+=1
    counts.append(i)
    sm=0
    i=0
    for j in range(mx):
        if sm<=k:
            sm+=mxl[j]
            i+=1
        if sm<=k and j<mn:
            sm+=mnl[j]
            i+=1
    counts.append(i)
    print(max(counts))

Submission status: Wrong Answer

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

a_i = 0
b_i = 0
time = 0
counter = 0

while time < k:
    if a_i >= len(a_list) and b_i < len(b_list):
        time += b_list[b_i]
        #if time > k:
        #    break
        counter += 1
        b_i += 1
    elif b_i >= len(b_list) and a_i < len(a_list):
        time += a_list[a_i]
        #if time > k:
        #    break
        counter += 1
        a_i += 1
    elif a_i >= len(a_list) and b_i >= len(b_list):
        break
    else:
        if a_list[a_i] <= b_list[b_i]:
            time += a_list[a_i]
            #if time > k:
            #    break
            counter += 1
            a_i += 1
        else:
            time += b_list[b_i]
            #if time > k:
            #    break
            counter += 1
            b_i += 1

print(counter)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int, input().split())
a_lst = [int(i) for i in input().split() if int(i) < k]
b_lst = [int(i) for i in input().split() if int(i) < k]

sum_lst = sorted(a_lst + b_lst)
count = 0
time = 0

for i in range(len(a_lst)+len(b_lst)):
    if time >= k:
        break
    count += 1
    time += sum_lst.pop(0)
if time > k:
    print(count-1)
else:
    print(count)