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

sum_a = [0]
sum_b = [0]

for i in range(n):
    sum_a.append(sum_a[i] + a[i])
for j in range(m):
    sum_b.append(sum_b[j] + b[j])

temp = 0
j = m
ans = 0
for i in range(n+1):
    if sum_a[i] > k:
        temp = i -1
        if temp > ans:
            ans = temp
        break
    else:
        while k - sum_a[i] < sum_b[j]:
            j -= 1
        temp = i + j
        if temp > ans:
            ans = temp
            
print(temp)

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

sum_a = [0]
sum_b = [0]

for i in range(n):
    sum_a.append(sum_a[i] + a[i])
for j in range(m):
    sum_b.append(sum_b[j] + b[j])

temp = 0
j = m
ans = 0
for i in range(n+1):
    if sum_a[i] > k:
        break
    else:
        while k - sum_a[i] < sum_b[j]:
            j -= 1
        temp = i + j
        if temp > ans:
            ans = temp
            
print(temp)

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
# Aだけの場合
maxt = 0
total = 0
for i in range(len(A)):
    total += A[i]
    if total < K :
        #print("A",maxt,i)
        maxt = max(i+1,maxt)

total = 0    
for i in range(len(B)):
    total += B[i]
    if total < K :
        #print("B",maxt,i)
        maxt = max(i+1,maxt)

#
totalA = 0
for i in range(len(A)):
    totalA += A[i]
    totalB = 0
    if totalA > K :
        break
    
    for j in range(len(B)):
        totalB += B[j]
        total = totalA + totalB
        if total > K :
            break
        #print(total, i, j)
        if totalA + totalB <= K :
            #print("C",maxt,i,j)
            maxt = max(i+j+2,maxt)

print(maxt)

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
# Aだけの場合
maxt = 0
total = 0
for i in range(len(A)):
    total += A[i]
    if total < K :
        #print("A",maxt,i)
        maxt = max(i+1,maxt)

total = 0    
for i in range(len(B)):
    total += B[i]
    if total < K :
        #print("B",maxt,i)
        maxt = max(i+1,maxt)

#
totalA = 0
for i in range(len(A)):
    totalA += A[i]
    totalB = 0
    for j in range(len(B)):
        totalB += B[j]
        total = totalA + totalB
        #print(total, i, j)
        if totalA + totalB <= K :
            #print("C",maxt,i,j)
            maxt = max(i+j+2,maxt)

print(maxt)

Submission status: Wrong Answer

Solution code:
alen, blen, time = map(int, input().split())
abooks = list(map(int, input().split()))
bbooks = list(map(int, input().split()))

counter = 0
reading_time = 0
while time > 0:
    if len(abooks) < 1 and len(bbooks) < 1:
        break
    elif len(abooks) < 1 and len(bbooks) > 0:
        reading_time = bbooks.pop(0)
    elif len(abooks) > 0 and len(bbooks) < 1:
        reading_time = abooks.pop(0)
    elif abooks[0] < bbooks[0]:
        reading_time = abooks.pop(0)
    else:
        reading_time = bbooks.pop(0)
    time -= reading_time
    if time >= 0:
        counter += 1

print(counter)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
 
ans = 0
time = 0
a_time = 0
temp = 0
if a[0] > k:
    for j in range(len(b)):
        time += b[j]
        if time <= k:
            temp += 1
        else:
            break
    ans = temp
else:
    for i in range(len(a)):
        a_time += a[i]
        if a_time > k:
            break
        else:
            time = a_time
            for j in range(len(b)):
                time += b[j]
                if time <= k:
                    temp = i + 1 + j + 1
                    if temp > ans:
                        ans = temp
                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
time = 0
a_time = 0
temp = 0
if a[0] > k:
    for j in range(len(b)):
        time += b[j]
        if time <= k:
            temp += 1
        else:
            break
    ans = temp
    print(ans)

for i in range(len(a)):
    a_time += a[i]
    if a_time > k:
        break
    else:
        time = a_time
        for j in range(len(b)):
            time += b[j]
            if time <= k:
                temp = i + 1 + j + 1
                if temp > ans:
                    ans = temp
            else:
                break
            
print(ans)

Submission status: Wrong Answer

Solution code:
A,B,K=map(int,input().split())
List_A = list(map(int, input().split()))
List_B = list(map(int, input().split()))
SumListA=[]
SumListA.append(0)
SumListB=[]
SumListB.append(0)
res =0
a=0
for i in range(A):
  SumListA.append(SumListA[i]+List_A[i])
for i in range(B):
  SumListB.append(SumListB[i]+List_B[i])

j=B
for i in range(A):
  if SumListA[i] > K:
    break
  while K-SumListA[i] < SumListB[j]:
    j += -1
  res = max(i+j,res)
print(res)

Submission status: Wrong Answer

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

a = [0]
b = [0]
aa = 0
bb = 0
for i in A:
    aa += i
    a.append(aa)
for j in B:
    bb += j
    b.append(bb)

ans = 0
cnt = 0
lb = 1
for i in reversed(range(len(a))):
    cnt = a[i]
    if(cnt > K):
        continue
    for j in range(lb, len(b)):
        tmp = cnt + b[j]
        if(tmp > K):
            lb = j
            break
        else:
            ans = max(i+j, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
A,B, K=map(int,input().split())
List_A = list(map(int, input().split()))
List_B = list(map(int, input().split()))
SumListA=[]
SumListA.append(0)
res =0
a=0
for i in range(A):
  a = SumListA[i]+List_A[i]
  if a < K:
    SumListA.append(a)
  else:
    break
SumListB=[]
SumListB.append(0)
for i in range(B):
  a = SumListB[i]+List_B[i]
  if a < K:
    SumListB.append(a)
  else:
    break
for i in range(len(SumListA)):
  for j in range(len(SumListB)-1,0,-1):
    if K-SumListA[i] < SumListB[j]:
      pass
    else:
      res = max(i+j,res)
      break
print(res)

Submission status: Wrong Answer

Solution code:
A,B, K=map(int,input().split())
List_A = list(map(int, input().split()))
List_B = list(map(int, input().split()))
SumListA=[]
SumListA.append(0)
res =0
a=0
for i in range(A):
  a = SumListA[i]+List_A[i]
  if a < K:
    SumListA.append(a)
  else:
    break
SumListB=[]
SumListB.append(0)
for i in range(B):
  a = SumListB[i]+List_B[i]
  if a < K:
    SumListB.append(a)
  else:
    break
for i in range(len(SumListA)):
  for j in range(len(SumListB)):
    a = SumListA[i]+SumListB[j] 
    if a <= K:
      if i+j>res:
        res = i+j
    else:
      break
print(res)

Submission status: Wrong Answer

Solution code:
A,B, K=map(int,input().split())
List_A = list(map(int, input().split()))
List_B = list(map(int, input().split()))
SumListA=[]
SumListA.append(List_A[0])
res =0
a=0
for i in range(1,A):
  a = SumListA[i-1]+List_A[i]
  if a < K:
    SumListA.append(a)
  else:
    break
SumListB=[]
SumListB.append(List_B[0])
for i in range(1,B):
  a = SumListB[i-1]+List_B[i]
  if a < K:
    SumListB.append(a)
  else:
    break
for i in range(len(SumListA)):
  for j in range(len(SumListB)):
    a = SumListA[i]+SumListB[j] 
    if a <= K:
      if i+j+2>res:
        res = i+j+2

print(res)

Submission status: Wrong Answer

Solution code:
A,B, K=map(int,input().split())
List_A = list(map(int, input().split()))
List_B = list(map(int, input().split()))
SumListA=[]
SumListA.append(List_A[0])
res =0
a=0
for i in range(1,A):
  a = SumListA[i-1]+List_A[i]
  if a < K:
    SumListA.append(a)
  else:
    break
SumListB=[]
SumListB.append(List_B[0])
for i in range(1,B):
  a = SumListB[i-1]+List_B[i]
  if a < K:
    SumListB.append(a)
  else:
    break
print(SumListA,SumListB)
for i in range(len(SumListA)):
  for j in range(len(SumListB)):
    a = SumListA[i]+SumListB[j] 
    if a <= K:
      if i+j+2>res:
        res = i+j+2

print(res)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

n,m,k = map(int,readline().split())
a = list(map(int,readline().split()))
b = list(map(int,readline().split()))

csuma = [0]
csumb = [0]
for ai in a:
    csuma.append(csuma[-1]+ai)
for bi in b:
    csumb.append(csumb[-1]+bi)


ans = 0
for i,csumai in enumerate(csuma):
    ng = m+1
    ok = -1
    while ng - ok > 1:
        mid = (ok + ng)//2
        if csumb[mid] <= k-csumai:
            ok = mid
        else:
            ng = mid
    if ok > 0:
        ans = max(ans,i+ok)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

n,m,k = map(int,readline().split())
a = list(map(int,readline().split()))
b = list(map(int,readline().split()))

csuma = [0]
csumb = [0]
for ai in a:
    csuma.append(csuma[-1]+ai)
for bi in b:
    csumb.append(csumb[-1]+bi)

ans = 0
for i,csumai in enumerate(csuma):
    ng = m+1
    ok = -1
    while ng - ok > 1:
        mid = (ok + ng)//2
        if csumb[mid] <= k-csumai:
            ok = mid
        else:
            ng = mid
    if ok <= 0:
        ans = max(ans,i+ok)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

n,m,k = map(int,readline().split())
a = list(map(int,readline().split()))
b = list(map(int,readline().split()))

csuma = [0]
csumb = [0]
for ai in a:
    csuma.append(csuma[-1]+ai)
for bi in b:
    csumb.append(csumb[-1]+bi)


ans = 0
for i,csumai in enumerate(csuma):
    ng = m+1
    ok = 0
    while ng - ok > 1:
        mid = (ok + ng)//2
        if csumb[mid] <= k-csumai:
            ok = mid
        else:
            ng = mid
    if ok != 0:
        ans = max(ans,i+ok)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

n,m,k = map(int,readline().split())
a = list(map(int,readline().split()))
b = list(map(int,readline().split()))
a,b = a[::-1],b[::-1]
cnt = 0
while k > 0:
    if len(a) != 0 and len(b) != 0:
        cnt += 1
        if a[-1] > b[-1]:
            k -= b.pop()
        else:
            k -= a.pop()
    elif len(a) != 0:
        cnt += 1
        k -= a.pop()
    elif len(b) != 0:
        cnt += 1
        k -= b.pop()
    else:
        break
print(cnt-1 if k < 0 else cnt)

Submission status: Wrong Answer

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

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

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

import bisect

ans=0
for i,r in enumerate(ruia):
    nokori =K-r
    if nokori>=0:
        n_nokori = bisect.bisect(ruib,nokori)
        ans = max(ans,i+n_nokori)
    print(i,r,nokori,n_nokori,ans)
print(ans)

Submission status: Wrong Answer

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

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

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

import bisect

ans=0
for i,r in enumerate(ruia):
    nokori =K-r
    if nokori>0:
        n_nokori = bisect.bisect(ruib,nokori)
        ans = max(ans,i+n_nokori)

print(ans)

Submission status: Wrong Answer

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

ruia = [0]*N
ruia[0]=A[0]
for i in range(1,N):
    ruia[i]=ruia[i-1]+A[i]
    
ruib = [0]*M
ruib[0]=B[0]
for i in range(1,M):
    ruib[i]=ruib[i-1]+B[i]

import bisect
ans=0
for i,r in enumerate(ruia):
    nokori =K-r
    if nokori>0:
        n_nokori = bisect.bisect(ruib,nokori)
        ans = max(ans,i+1+n_nokori)

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
import bisect
N,M, K = map(int,input().split())
A = map(int,input().split())
B = map(int,input().split())
accum_A = list(accumulate(A))
accum_B = list(accumulate(B))
max_num = 0
for i in range(N):
    if accum_A[i]< K:
        reside = K-accum_A[i]
        point_1 = bisect.bisect(accum_B,reside)+1
        point_2 = bisect.bisect_left(accum_B,reside)+1
        if point_1!=point_2:
            temp_max=point_1 + 1
        else:
            temp_max=point_2 + 1
        max_num = max(max_num,temp_max)
            
print(max_num)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
N,M, K = map(int,input().split())
A = map(int,input().split())
B = map(int,input().split())
accum_A = list(accumulate(A))
accum_B = list(accumulate(B))
max_num = 0
for i in range(N):
    if accum_A[i]<= K:
        reside = K-accum_A[i]
        temp_max = i+1
        for j in range(M):
            if accum_B[j] <= reside:
                temp_max=i+j+2
            else:
                break;
        max_num = max(max_num,temp_max)
print(max_num)

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]

time = 0
count = 0
for i in range(N + M):
    if len(A) > 0 and len(B) > 0:
        if A[-1] <= B[-1]:
            time += A[-1]
            count += 1
            A.pop()
        else:
            time += B[-1]
            count += 1
            B.pop()
    elif len(A) <= 0 and len(B) > 0:
        time += B[-1]
        count += 1
        B.pop()
    elif len(B) <= 0 and len(A) > 0:
        time += A[-1]
        count += 1
        A.pop()
    if time > K:
        count -= 1
        break
    elif time == K:
        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()))
c = a + b
c.sort()

total = 0
ans = 0
for i in range(len(c)):
    total += c[i]
    if total > k:
        break
    else:
       ans += 1

print(ans)

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

index_a = -1
index_b = 0
num_books = 0
now_times = 0

for a in A :
  if now_times + a <= K :
    num_books += 1
    now_times += a
    index_a += 1

temp_books = num_books
temp_times = now_times
  
while index_a > -2 :
  while index_b < len(B) and temp_times + B[index_b] <= K :
    temp_books += 1
    temp_times += B[index_b]
    index_b += 1
    if temp_books > num_books :
      num_books = temp_books
  temp_books -= 1
  temp_times -= A[index_a]
  index_a -= 1
      
print(num_books)

Submission status: Wrong Answer

Solution code:
from collections import deque

N, M, K = map(int, input().split())
A = deque([int(x) for x in input().split()])
B = deque([int(x) for x in input().split()])
tsundoku = 0

while K > 0:
    if not A:
        K -= B.popleft()
    elif not B:
        K -= A.popleft()
    elif A[0] < B[0]:
        K -= A.popleft()
    else:
        K -= B.popleft()
    if K >= 0:
        tsundoku += 1

print(tsundoku)

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

t=sum(a)
l=n-1
r=0
ans=0
while r<m and l>-1:
    if t>k:
        t-=a[l]
        l-=1
    else:
        t+=b[r]
        r+=1
    if t<=k:
        if r+l+1>ans:
            ans=r+l+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()))

t=sum(a)
l=n-1
r=0
ans=0
while r<m and l>0:
    if t>k:
        t-=a[l]
        l-=1
    else:
        t+=b[r]
        r+=1
    if t<=k:
        if r+l+1>ans:
            ans=r+l+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,b = [0],[0]
n,m,ans = 0, 0, 0
 
for i in range(N):
  a.append(a[i]+A[i])
  if a[i+1] <= K:
    n = i+1
for i in range(M):
  b.append(b[i]+B[i])
  if b[i+1] <= K:
    m = i+1

if n == N or m == M:
  for i in range(N+M+2,max(n,m),-1):
    tmp = 0
    for j in range(min(N+1,i+1),max(0,i-M),-1):
      if a[j]+b[i-j] > K:
        tmp = 1
        ans = i
        break
    if tmp == 0:
      break
else:
  for i in range(max(n,m),N+M+2):
    tmp = 0
    for j in range(max(0,i-M),min(N+1,i+1)):
      if a[j]+b[i-j] <= K:
        tmp = 1
        ans = i
        break
    if tmp == 0:
      break

print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
 
a,b = [0],[0]
n,m,ans = 0, 0, 0
 
for i in range(N):
  a.append(a[i]+A[i])
  if a[i+1] <= K:
    n = i+1
for i in range(M):
  b.append(b[i]+B[i])
  if b[i+1] <= K:
    m = i+1

if n == N and m == M:
  for i in range(N+M+2,max(n,m),-1):
    tmp = 0
    for j in range(min(N+1,i+1),max(0,i-M),-1):
      if a[j]+b[i-j] > K:
        tmp = 1
        ans = i - 1
        break
    if tmp == 0:
      break
else:
  for i in range(max(n,m),N+M+2):
    tmp = 0
    for j in range(max(0,i-M),min(N+1,i+1)):
      if a[j]+b[i-j] <= K:
        tmp = 1
        ans = i
        break
    if tmp == 0:
      break

print(ans)

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()))
a = [sum(a[:i+1]) for i in range(len(a))]
b = [sum(b[:i+1]) for i in range(len(b))]
ans = 0
for i in range(n):
    for j in reversed(range(m)):
        if a[i]+b[j]<=k:
            ans = max(ans, i+j+2)
            m=j+1
            break
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()))

i = 0
j = 0
count = 0
a = [0]*N
b = [0]*M
ans = 0

sum = 0
for i in range(N):
    sum += A[i]
    a[i] = sum
sum = 0
for j in range(M):
    sum += B[j]
    b[j] = sum

for i in range(N):
    if a[i] <= K:
        ind = bisect.bisect_right(b, K-a[i])
        ans = max(ans, ind+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()))
a.append(0)
b.append(0)
t=0
i=0
j=0
ans=0
while t<=k:
  if t+min(a[i],b[j])<=k and min(a[i],b[j])!=0:
    t=t+min(a[i],b[j])
    ans+=1
    if a[i]>=b[j]:
      j+=1
    else:
      i+=1
  elif t+max(a[i],b[j])<=k and min(a[i],b[j])==0 and max(a[i],b[j])!=0:
    t=t+max(a[i],b[j])
    ans+=1
    if a[i]>=b[j]:
      i+=1
    else:
      j+=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()))
 
a,b = [0],[0]
ans = 0
 
for i in range(N):
  a.append(a[i]+A[i])
for i in range(M):
  b.append(b[i]+B[i])
  
for i in range(N+M+2):
  tmp = 0
  for j in range(min(M+1,i+1)):
    if i-j > N:
      continue
    if a[i-j]+b[j] < K:
      tmp = 1
      ans = i
      break
  if tmp == 0:
    break

print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
 
a,b = [0],[0]
ans = 0
 
for i in range(N):
  a.append(a[i]+A[i])
for i in range(M):
  b.append(b[i]+B[i])
  
for i in range(N+M+2):
  tmp = 0
  for j in range(min(N+1,i+1)):
    if i-j > M:
      continue
    if a[j]+b[i-j] < K:
      tmp = 1
      ans = i
      break
  if tmp == 0:
    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()))
 
sum = []
a,b = [0],[0]
ans = 0
 
for i in range(N):
  a.append(a[i]+A[i])
for i in range(M):
  b.append(b[i]+B[i])
  
for i in range(N+M+2):
  tmp = 0
  for j in range(i):
    if a[j]+b[i-j] < K:
      tmp = 1
      ans = i
      break
  if tmp == 0:
    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()))
 
sum = []
a,b = [0],[0]
ans = 0
 
for i in range(N):
  a.append(a[i]+A[i])
for i in range(M):
  b.append(b[i]+B[i])
  
for i in range(N+M+1):
  tmp = 0
  for j in range(i):
    if a[j]+b[i-j] < K:
      tmp = i+1
      ans = max(ans,i)
      break
  if tmp ==0:
    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()))
 
sum = []
a,b = [0],[0]
ans = 0
 
for i in range(N):
  a.append(a[i]+A[i])
for i in range(M):
  b.append(b[i]+B[i])
  
for i in range(N+M+1):
  tmp = 0
  for j in range(i):
    if a[j]+b[i-j] < K:
      tmp = i
      ans = max(ans,tmp)
      break
  if tmp ==0:
    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()))
 
sum = []
a,b = [0],[0]
ans = 0
 
for i in range(N):
  a.append(a[i]+A[i])
for i in range(M):
  b.append(b[i]+B[i])
  
for i in range(N+1):
  if a[i] > K:
    break
  for j in range(M+1):
    if a[i]+b[M-j] < K:
      ans = max(ans,i+M-j)
      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()))
 
sum = []
a,b = [0],[0]
ans = 0
 
for i in range(N):
  a.append(a[i]+A[i])
for i in range(M):
  b.append(b[i]+B[i])
  
for i in range(N):
  if a[i+1] > K:
    break
  for j in range(M):
    if a[i+1]+b[j+1] > K:
      ans = max(ans,i+j+1)
      break

print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
 
sum = []
a,b = [0],[0]
ans = 0
 
for i in range(N):
  a.append(a[i]+A[i])
for i in range(M):
  b.append(b[i]+B[i])
  
for i in range(N):
  if a[i+1] > K:
    break
  for j in range(M):
    if b[j+1] > K:
      break
    if a[i+1]+b[j+1] > K:
      ans = max(ans,i+j+1)
      break

print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
 
sum = []
a,b = [0],[0]
ans = 0
 
for i in range(N):
  a.append(a[i]+A[i])
for i in range(M):
  b.append(b[i]+B[i])

for i in range(N):
  if a[i+1] > K:
    break
  for j in range(M):
    if b[j+1] > K:
      break
    if a[i+1]+b[j+1] > K:
      ans = max(ans,i+j)
      break

print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c=map(int,input().split());
l=list(map(int,input().split()))

u=list(map(int,input().split()));
u.extend(l)
u.sort()

m=0;
count=0;
for x in u:
    m=m+x;
    if(m<=c):
        count=count+1;
    elif(m>c):
        break;
        
print(count)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    N,M,K = list(map(int,input().split()))
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    count,i_a,i_b = 0,0,0
    # ADD A item
    for i_a in range(len(A)):
        if K < A[i_a]:
            break
        else:
            count += 1
            K -= A[i_a]
    # replace B item
    
    for i in range((i_a-1),-1,-1):
        K += A[i]
        if i_b >= len(B):
            break
        while True:
            if i_b >= len(B):
                break
            if K < B[i_b] :
                break
            else :
                K -= B[i_b]
                i_b += 1
        count = max(count,((i+1)+(i_b+1)))
    print(count)

Submission status: Wrong Answer

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

ans = 0

while A and B:
  if A[0] < B[0]:
    k -= A.pop(0)
  else: k -= B.pop(0); 
  if k > 0: ans += 1
  else: print(ans); exit()
  
while A:
    k -= A.pop(0)
    if k >= 0: ans += 1
    else: print(ans);exit()
while B:
    k -= B.pop(0)
    if k >= 0: ans += 1
    else: print(ans); exit()
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
x = min(m,n)
i = j = 0
ans = 0
while i < n and j < m:
  if A[i] < B[j]:
    k -= A[i]
    i += 1
  else: k -= B[j]; j += 1
  if k > 0: ans += 1
if i < n:
  for q in range(i,n):
    k -= A[q]
    if k >= 0: ans += 1
    else: print(ans);exit()
elif j < m:
  for q in range(j,m):
    k -= B[q]
    if k >= 0: ans += 1
    else: print(ans); exit()
print(ans)

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_cur = 0
b_cur = 0

total = 0
count = 0

while True:
  if a and b:
    if a[0] < b[0]:
      total += a.pop(0)
    else:
      total += b.pop(0)
  elif a:
    total += a.pop(0)
  elif b:
    total += b.pop(0)
  else:
    break
  
  if total > k:
    break

  count += 1
  
print(count)

Submission status: Wrong Answer

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

ans=0
for i in range(n+1):
    tb=0
    ta=sum(a[:i])
    if ta>k:
        break
    for j in range(m):
        tb += b[j]
        if tb + ta >k:
            break
        ans=max(ans,i+j+1)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

n, m, k = map(int, sys.stdin.readline().split())
 
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))

a_cur = 0
b_cur = 0

total = 0
count = 0

while True:
  if a and b:
    if a[0] < b[0]:
      total += a.pop(0)
    else:
      total += b.pop(0)
  elif a:
    total += a.pop(0)
  elif b:
    total += b.pop(0)
  else:
    break
  
  if total > k:
    break

  count += 1
  
print(count)

Submission status: Wrong Answer

Solution code:
import sys

n, m, k = map(int, sys.stdin.readline().split())
 
a = list(map(float, sys.stdin.readline().split()))
b = list(map(float, sys.stdin.readline().split()))

a_cur = 0
b_cur = 0

total = 0
count = 0

while True:
  if a and b:
    if a[0] < b[0]:
      total += a.pop(0)
    else:
      total += b.pop(0)
  elif a:
    total += a.pop(0)
  elif b:
    total += b.pop(0)
  else:
    break
  
  if total > k:
    break

  count += 1
  
print(count)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n, m, k = rm()
a = rl()
b = list(itertools.accumulate(rl()))
if a[0] > k:
    ans = 0
else:
    left = 0
    right = m
    while right - left > 1:
        j = (left + right) // 2
        if b[j] > k:
            right = j
        else:
            left = j
    ans = left + 1
t = 0
b0 = b[0]
for cnt, i in enumerate(a, 1):
    t += i
    if t > k:
        break
    if b0 > t-k:
        ans = max(ans, cnt)
        continue
    left = 0
    right = m
    while right - left > 1:
        j = (left + right) // 2
        if b[j] > k-t:
            right = j
        else:
            left = j
    ans = max(ans, cnt + left + 1)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))

n, m, k = rm()
a = rl()
b = list(itertools.accumulate(rl()))
if a[0] > k:
    print(0)
    exit()
left = 0
right = m
while right - left > 1:
    j = (left + right) // 2
    if b[j] > k:
        right = j
    else:
        left = j
ans = left + 1
t = 0
for cnt, i in enumerate(a, 1):
    t += i
    if t > k:
        break
    left = 0
    right = m
    while right - left > 1:
        j = (left + right) // 2
        if b[j] > k-t:
            right = j
        else:
            left = j
    ans = max(ans, cnt + left + 1)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools

rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))

n, m, k = rm()
a = rl()
b = list(itertools.accumulate(rl()))
left = 0
right = m
while right - left > 1:
    j = (left + right) // 2
    if b[j] > k:
        right = j
    else:
        left = j
ans = left + 1
t = 0
for cnt, i in enumerate(a, 1):
    t += i
    if t > k:
        break
    left = 0
    right = m
    while right - left > 1:
        j = (left + right) // 2
        if b[j] > k-t:
            right = j
        else:
            left = j
    ans = max(ans, cnt + left + 1)
print(ans)