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(' '))
list_a = list(map(int, input().split(' ')))
list_b = list(map(int, input().split(' ')))
 
a_sum=[list_a[0]]
for i in range(1, n):
  a_sum.append(list_a[i]+a_sum[i-1])
  
b_sum=[list_b[0]]
for i in range(1, m):
  b_sum.append(list_b[i]+b_sum[i-1])

  
ans=0 
if (a_sum[0]>k) and (b_sum[0]>k):
  print(0)
else:
  for j in range(m):
    if b_sum[j]<=k:
      ans=max(ans, j+1)
  j=m-1
  for i in range(n):
    if a_sum[i]<=k:
      ans=max(ans, i+1)
      while a_sum[i] + b_sum[j] > k and j>0:
        j-=1
      if a_sum[i]+b_sum[j]<=k:
        ans=max(ans, i+j+2)

print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split(' '))
list_a = list(map(int, input().split(' ')))
list_b = list(map(int, input().split(' ')))
 
a_sum=[list_a[0]]
for i in range(1, n):
  a_sum.append(list_a[i]+a_sum[i-1])
  
b_sum=[list_b[0]]
for i in range(1, m):
  b_sum.append(list_b[i]+b_sum[i-1])

  
ans=0 
if a_sum[0]>k:
  if b_sum[0]>k:
    print(0)
  else:
    for j in range(m):
      if b_sum[j]<=k:
        ans=max(ans, j+1)
    print(ans)
else:
  j=m-1
  for i in range(n):
    if a_sum[i]<=k:
      ans=max(ans, i+1)
    while a_sum[i] + b_sum[j] > k and j>0:
      j-=1
    if a_sum[i]+b_sum[j]<=k:
      ans=max(ans, i+j+2)
  print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split(' '))
list_a = list(map(int, input().split(' ')))
list_b = list(map(int, input().split(' ')))
 
a_sum=[list_a[0]]
for i in range(1, n):
  a_sum.append(list_a[i]+a_sum[i-1])
  
b_sum=[list_b[0]]
for i in range(1, m):
  b_sum.append(list_b[i]+b_sum[i-1])

  
ans=0 
if a_sum[0]>k:
  if b_sum[0]>k:
    print(0)
  else:
    for j in range(m):
      if b_sum[j]<=k:
        ans=max(ans, j+1)
        print(ans)
else:
  j=m-1
  for i in range(n):
    if a_sum[i]<=k:
      ans=max(ans, i+1)
    while a_sum[i] + b_sum[j] > k and j>0:
      j-=1
    if a_sum[i]+b_sum[j]<=k:
      ans=max(ans, i+j+2)
  print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split(' '))
list_a = list(map(int, input().split(' ')))
list_b = list(map(int, input().split(' ')))
 
a_sum=[list_a[0]]
for i in range(1, n):
  a_sum.append(list_a[i]+a_sum[i-1])
  
b_sum=[list_b[0]]
for i in range(1, m):
  b_sum.append(list_b[i]+b_sum[i-1])

  
ans=0 
if a_sum[0]>k:
  if b_sum[0]>k:
    print(0)
  else:
    for j in range(m):
      if b_sum[j]<=k:
        ans=max(ans, j+1)
        print(ans)
else:
  for i in range(n):
    if a_sum[i]<=k:
      ans=max(ans, i+1)
    j=m-1
    while a_sum[i]+b_sum[j]>k and j>=0:
      j-=1
    if a_sum[i]+b_sum[j]<=k:
      ans=max(ans, i+j+2)
  print(ans)

Submission status: Wrong Answer

Solution code:
l1 = input()
l2 = input()
l3 = input()

n, m, k = map(int, l1.split(' '))
a_l = iter(map(int, l2.split(' ')))
b_l = iter(map(int, l3.split(' ')))

num = 0

a = next(a_l)
b = next(b_l)

total = 0

def next_iter(l):
    try:
        return next(l)
    except StopIteration:
        return None

while True:
    changed = False
    if a and b:
        if a <= b and a <= k:
            k -= a
            a = next_iter(a_l)
            num += 1
            changed = True
        elif b <= k:
            k -= b
            b = next_iter(b_l)
            num += 1
            changed = True
    elif a and a <= k:
        k -= a
        a = next_iter(a_l)
        num += 1
        changed = True
    elif b and b <= k:
        k -= b
        b = next_iter(b_l)
        num += 1
        changed = True

    if not changed:
        break

print(num)

Submission status: Wrong Answer

Solution code:
l1 = input()
l2 = input()
l3 = input()

n, m, k = map(int, l1.split(' '))
a_l = iter(map(int, l2.split(' ')))
b_l = iter(map(int, l3.split(' ')))

num = 0

a = next(a_l)
b = next(b_l)

while True:
    changed = False
    if a and (not b or a <= b):
        if k >= a:
            k -= a
            try:
                a = next(a_l)
            except StopIteration:
                a = None
            num += 1
            changed = True
    elif b:
        if k >= b:
            k -= b
            try:
                b = next(b_l)
            except StopIteration:
                b = None
            num += 1
            changed = True

    if not changed:
        break

print(num)

Submission status: Wrong Answer

Solution code:
n, m, k = (int(x) for x in input().split())
a = [99999999]*200000
b = [99999999]*200000
 
a = [int(e) for e in input().split()]
b = [int(e) for e in input().split()]
 
time = 0
satsu = 0
 
while time < k:
    an = 0
    bn = 0
    if a[an] >= b[bn]:
        time += b[bn]
        bn = bn+1
        satsu = satsu + 1
        
        
            
            
    
    elif b[bn] >= a[an]:
        time += a[bn]
        an = an+1
        satsu = satsu + 1
        
        
 
print(satsu-1)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
l_a = list(map(int, input().split()))
l_b = list(map(int, input().split()))
num = 0
ans = 0

while num <= k:
  if len(l_a)==0 and len(l_b)==0:
    print(ans)
    break
  if len(l_a) == 0:
    num = num + l_b[0]
    l_b.pop(0)
    ans += 1
  
  elif len(l_b) == 0:
    num = num + l_a[0]
    l_a.pop(0)
    ans += 1
  
  else:
    if l_a[0] < l_b[0]:
      num = num + l_a[0]
      l_a.pop(0)
    else:
      num = num + l_b[0]
      l_b.pop(0)
  #  print(l_a)
   # print(l_b)
    #print(num)
    ans += 1

if num > k:

  ans = 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()))
time = 0
count = 0
while time <= K:
    if len(A) != 0 and len(B) != 0:
        if A[0] <= B[0]:
            time += A.pop(0)
            count += 1
        else:
            time += B.pop(0)
            count += 1
    elif len(A) == 0 and len(B) != 0:
        time += B.pop(0)
        count += 1
    elif len(B) == 0 and len(A) != 0:
        time += A.pop(0)
        count += 1
    elif len(A) == 0 and len(B) == 0:
        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()))
time = 0
count = 0
while time < K:
    print(time)
    if len(A) != 0 and len(B) != 0:
        if A[0] <= B[0]:
            time += A.pop(0)
            count += 1
        else:
            time += B.pop(0)
            count += 1
    elif len(A) == 0 and len(B) != 0:
        time += B.pop(0)
        count += 1
    elif len(B) == 0:
        time += A.pop(0)
        count += 1
print(count-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()))

b_li = [0]
b_ = 0

for B_ in B:
    b_ = b_ + B_
    b_li.append(b_)

book_max = 0
book_cnt_a = 0
book_cnt_ab = 0
a_ = 0
book_cnt_ab = M

for i in range(N+1):
    while (b_li[book_cnt_ab-1] + a_) > K:
        book_cnt_ab = book_cnt_ab - 1
        if book_cnt_ab < 0: break
    if book_cnt_ab < 0: break
    if (book_max <= book_cnt_ab + book_cnt_a):
            book_max = book_cnt_ab + book_cnt_a
    book_cnt_a = book_cnt_a + 1
    if i >= N: break
    a_ = a_ + A[i]

print(book_max)

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_li = [0]
a_ = 0
b_li = [0]
b_ = 0

for A_ in A:
    a_ = a_ + A_
    a_li.append(a_)

for B_ in B:
    b_ = b_ + B_
    b_li.append(b_)

b_li.reverse()

book_max = 0
book_cnt_a = 0
book_cnt_ab = 0

for a_ in a_li:
    book_cnt_ab = M
    for b_ in b_li:
        if (a_ + b_) < K:
            if (book_max <= book_cnt_ab + book_cnt_a):
                book_max = book_cnt_ab + book_cnt_a
            break
        book_cnt_ab = book_cnt_ab - 1
    book_cnt_a = book_cnt_a + 1

print(book_max)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
data_a=list(map(int,input().split())) #n個の行列
data_b=list(map(int,input().split())) #m個の行列
sum_a=sum(data_a)
sum_b=sum(data_b)


def count_b(number):
    s=0
    sub=number
    for i in range(m):
        if data_b[i] <= sub:
            s += 1
            sub -= data_b[i]
        else:
            break
    return s

def count_a(number):
    s=0
    sub=number
    for i in range(m):
        if data_a[i] <= sub:
            s += 1
            sub -= data_a[i]
        else:
            break
    return s

        
if sum_a <= k:
    first_count=count_b(k-sum_a)+n
    count=first_count
    for i in range(n+1):
        if count_b(k-sum(data_a[:i]))+i > count:
            count=count_b(k-sum(data_a[:i]))+i
    print(count)
    
elif sum_a >= 1:
    first_count=count_a(k)
    count=first_count
    for i in range(first_count+1):
        if count_b(k-sum(data_a[:i]))+i > count:
            count=count_b(k-sum(data_a[:i]))+i
    print(count)

else:
    print(count_b(k))

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

for _ in range(n+m):
    if len(A) > 0 and len(B) > 0:
        if A[0] > B[0]:
            C.append(B[0])
            B.pop(0)
        else:
            C.append(A[0])
            A.pop(0)
    elif A == []:
        C.extend(B)
        break
    elif B == []:
        C.extend(A)
        break

total = 0
for i in range(n+m):
    total += C[i]
    if total > k:
        break
if total > k:
    print(i)
else:
    print(i+1)

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
data_a=list(map(int,input().split())) #n個の行列
data_b=list(map(int,input().split())) #m個の行列
sum_a=sum(data_a)
sum_b=sum(data_b)


def count_b(number):
    s=0
    sub=number
    for i in range(m):
        if data_b[i] <= sub:
            s += 1
            sub -= data_b[i]
        else:
            break
    return s

def count_a(number):
    s=0
    sub=number
    for i in range(m):
        if data_a[i] <= sub:
            s += 1
            sub -= data_a[i]
        else:
            break
    return s

        
if sum_a <= k:
    first_count=count_b(k-sum_a)+n
    count=first_count
    for i in range(n+1):
        if count_b(k-sum(data_a[:i]))+i > count:
            count=count_b(k-sum(data_a[:i]))+i
    print(count)
    
else:
    first_count=count_a(k)
    count=first_count
    for i in range(first_count+1):
        if count_b(k-sum(data_a[:i]))+i > count:
            count=count_b(k-sum(data_a[:i]))+i
    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()))

book_max = 0
book_cnt = 0

Asum = 0
for ia in range(N+1):
    Bsum = 0
    for ib in range(M+1):
        if K < (Asum + Bsum): break
        book_cnt = book_cnt + 1
        if book_max < (book_cnt - 0):
            book_max = book_cnt
        if ib == M: break
        Bsum = Bsum + B[ib]
    book_cnt = ia + 1
    if book_max < (book_cnt - 0):
        book_max = book_cnt
    if ia == N: break
    Asum = Asum + A[ia]

print(book_max)

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

book_max = 0
book_cnt = 0

Asum = 0
for ia in range(N+1):
    Bsum = 0
    for ib in range(M+1):
        if K < (Asum + Bsum): break
        if ib == M: break
        Bsum = Bsum + B[ib]
        book_cnt = book_cnt + 1
        if book_max < (book_cnt - 0):
            book_max = book_cnt
    if ia == N: break
    Asum = Asum + A[ia]
    book_cnt = ia + 1
    if book_max < (book_cnt - 0):
        book_max = book_cnt

print(book_max)

Submission status: Wrong Answer

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

L1=list(map(int,input().split()))
L2=list(map(int,input().split()))

L=L1+L2
L.sort()
result=0
time=0

for i in range(n+m):
    if result<=k:
        result+=L[i]
        time=i+1
        if result>k:
            time=i
            break

print(time)

Submission status: Wrong Answer

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

L1=list(map(int,input().split()))
L2=list(map(int,input().split()))

L=L1+L2
L.sort()
result=0


for i in range(n+m):
    if result<=k:
        global time
        result+=L[i]
        time=i+1
        if result>k:
            time=i
            break

print(time)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
import copy


# 引数が一つだけのやつ
# n = int(input())
# 引数が複数あるやつ（全部数字）
target_1 = [int(x) for x in input().split()]

N = target_1[0]
M = target_1[1]
K = target_1[2]

target_2 = [int(x) for x in input().split()]
target_2.reverse()
target_3 = [int(x) for x in input().split()]
target_3.reverse()
result = 0

for i in range(1, N + 1):
    # i: 冊数
    left = K - sum(target_2[0:i])
    if left < 0:
        break
    result = max(result, i - 1)
    for j in range(1, M + 1):
        # j: 冊数
        left_t = left - sum(target_3[0:j])
        if left_t < 0:
            break
        result = max(result, i + j)


print(result)

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

# print("N=",N)
# print("M=",M)
# print("K=",K)
# print("A=",A)
# print("B=",B)

A_accumulate_cost = [0]
lastCost = 0
for i in range(N):
    lastCost += A[i]
    A_accumulate_cost.append(lastCost)

B_accumulate_cost = [0]
lastCost = 0
for i in range(M):
    lastCost += B[i]
    B_accumulate_cost.append(lastCost)

# print(A_accumulate_cost)
# print(B_accumulate_cost)

max_num = 0
for i in range(N, 0, -1):
    A_cost = A_accumulate_cost[i]
    if (A_cost > K):
        continue

    for j in range(M, 0, -1):
        if (A_cost + B_accumulate_cost[j] <= K):
            if (i + j > max_num):
                max_num = i+j
            break

print(max_num)

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_cnt = 0
B_cnt = 0
time = 0
number = 0

while time <= K:
  if A_cnt<N and B_cnt<M: 
    if A_list[A_cnt] >= B_list[B_cnt]:
        time += B_list[B_cnt]
        B_cnt += 1
    else:
        time += A_list[A_cnt]
        A_cnt += 1
  elif A_cnt >= N and B_cnt >= M:
    A_cnt +=1
    break
  elif A_cnt >= N:
    time += B_list[B_cnt]
    B_cnt += 1
  elif B_cnt >= M:
    time += A_list[A_cnt]
    A_cnt += 1

print(A_cnt + B_cnt - 1)

Submission status: Wrong Answer

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

for n in range(N):
    for m in range(M):
        if sum(A[:N - n]) + sum(B[:M - m]) <= K:
            max_candidates.append(N - n + M - m)
            break

print(max(max_candidates))

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

# print("N=",N)
# print("M=",M)
# print("K=",K)
# print("A=",A)
# print("B=",B)

A_accumulate_cost = []
lastCost = 0
for i in range(N):
    lastCost += A[i]
    A_accumulate_cost.append(lastCost)

B_accumulate_cost = []
lastCost = 0
for i in range(M):
    lastCost += B[i]
    B_accumulate_cost.append(lastCost)

# print(A_accumulate_cost)
# print(B_accumulate_cost)

max_num = 0
for i in range(0,N):
    if (A_accumulate_cost[i] > K):
        break

    for j in range(0,M):
        if (A_accumulate_cost[i] + B_accumulate_cost[j] > K):
            break

        if( (i+1)+(j+1) > max_num):
            max_num = (i+1)+(j+1)

print(max_num)

Submission status: Wrong Answer

Solution code:
M,N,K = list(map(int,input().split(" ")))
A = list(map(int,input().split(" ")))
B = list(map(int,input().split(" ")))
read, Sum, rangenum = 0,0,0
rangenum = M if M>N else N
for i in range(rangenum):
    if Sum == K:break
    else:
        if Sum<K:
            if i<len(A):
                Sum+=A[i]
                read+=1
            if i<len(B):
                Sum+=B[i]
                read+=1
        else:
            read-=1
            break
print(read)

Submission status: Wrong Answer

Solution code:
M,N,K = list(map(int,input().split(" ")))
A = list(map(int,input().split(" ")))
B = list(map(int,input().split(" ")))
read, Sum, rangenum = 0,0,0
if M>N: rangenum = M
else: rangenum = N
for i in range(rangenum):
    if Sum == K:break
    else:
        if Sum<K:
            if i<len(A):
                Sum+=A[i]
                read+=1
            if Sum<K:
                if i<len(B):
                    Sum+=B[i]
                    read+=1
        else:
            read-=1
            break
print(read)

Submission status: Wrong Answer

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

acum1 = [0]
for i in range(n):
    acum1.append(acum1[-1]+arr1[i])

acum2 = [0]
for i in range(m):
    acum2.append(acum2[-1]+arr2[i])

ans = 0
j = m
for i in range(n):
    if acum1[i]>k:
        break
    while acum2[j]>k-acum1[i] and j>0:
        j -= 1
    ans = max(ans, i+j)
print(ans)

Submission status: Wrong Answer

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

acum1 = [0]
for i in range(n):
    acum1.append(acum1[-1]+a[i])

acum2 = [0]
for i in range(m):
    acum2.append(acum2[-1]+b[i])
ans = 0
j = m
for i in range(n+1):
    while acum2[j]>k-acum1[i] and j>0:
        j -= 1
    ans = max(ans,i+j)
print(ans)

Submission status: Wrong Answer

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

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

read = []
k_cnt = 0
cnt = 0

if A[0] <= K or B[0] <= K :
    while k_cnt < K :
        if len(A) == 0 and len(B) == 0 :
            break
        elif len(A) == 0 :
            read.append(B.pop(0))
            k_cnt += read[-1]
        elif len(B) == 0 :
            read.append(A.pop(0))
            k_cnt += read[-1]
        else : # 両方空ではない
            if A[0] > B[0] :
                read.append(B.pop(0))
                k_cnt += read[-1]
            else :
                read.append(A.pop(0))
                k_cnt += read[-1]
        cnt += 1


print(cnt)

Submission status: Wrong Answer

Solution code:
a,b,k=map(int,input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
A.append(10**9+1)
B.append(10**9+1)
p=0
q=0
s=0
books=0
for i in range(len(A)+len(B)):
    if A[p]<B[q] and s+A[p]<=k:
        s+=A[p]
        p+=1
        books+=1
    elif B[q]<=A[p] and s+B[q]<=k:
        s+=B[q]
        q+=1
        books+=1
    else:
        break
print(books)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
min = 0
cnt = 0
for i,k in enumerate(b):
    min += k
j = M
for i in range(N):
    while(j > 0 and min > K):
        j -= 1
        min -= b[j]
    if(min > K):
        break
    cnt = max(cnt, i + j)
    if(i == N):
        break
    min += a[i]
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()))
min = 0
cnt = 0
for i,k in enumerate(b):
    min += k
j = i
for i in range(N):
    while(j > 0 and min > K):
        j -= 1
        min -= b[j]
    if(min > K):
        break
    cnt = max(cnt, i + j)
    if(i == N):
        break
    min += a[i]
print(cnt)

Submission status: Wrong Answer

Solution code:
a,b,k=map(int,input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
C=A+B
C=sorted(C)

s=0
books=0
for i in range(len(C)):
    if s+C[i]<=k:
        s+=C[i]
        books+=1
    else:
        break
print(int(books))

Submission status: Wrong Answer

Solution code:
a,b,k=map(int,input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
C=A+B
C=sorted(C)

s=0
books=0
for i in range(len(C)):
    if s+C[i]<=k:
        s+=C[i]
        books+=1
    else:
        break
print(books)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
min = 0
ncnt = 0
mcnt = 0
cnt = 0
a.append(1000000005)
b.append(1000000005)
while min < K:
    if a[ncnt] <= b[mcnt]:
        if min + a[ncnt] > K:
            break
        min += a[ncnt]
        ncnt += 1
        cnt += 1
    else:
        if min + b[mcnt] > K:
            break
        min += b[mcnt]
        mcnt += 1
        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()))
min = 0
ncnt = 0
mcnt = 0
cnt = 0
a.append(1000000005)
b.append(1000000005)
while min < K:
    if a[ncnt] <= b[ncnt]:
        if min + a[ncnt] > K:
            break
        min += a[ncnt]
        ncnt += 1
        cnt += 1
    else:
        if min + b[ncnt] > K:
            break
        min += b[mcnt]
        mcnt += 1
        cnt += 1
print(cnt)

Submission status: Wrong Answer

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

l,r = 0,0
sum1 = 0
cnt = 0
while l < a or r < b:
    if sum1 < k:
        if A[l] <= B[r]:
            sum1 +=A[l]
            #print(A[l],B[r],sum1,cnt)
            if sum1 >k:
                print(cnt)
                exit()
            else:
                cnt +=1
                if l+1 <a:
                    l +=1
            
        else:
            sum1 += B[r]
            #print(A[l],B[r],sum1,cnt)
            if sum1 >k:
                print(cnt)
                exit()
            else:
                cnt +=1
                if r+1 <b:
                    r +=1

Submission status: Wrong Answer

Solution code:
def strToList(str,offset=0):
    res = [];
    for el in str.split(" "):
        if el!='':
            res.append(int(el)+offset)
    return res


[N,M,K] = strToList(input())
A = strToList(input())
B = strToList(input())

current_time = 0
current_value = 0
iA = 0
iB = 0

while iA<N:
    if current_time+A[iA]<=K:
        current_time+=A[iA]
        current_value+=1
        iA+=1
    else:
        break

max_value = current_value
iA-=1

while iA>=0 and iB<M:
    if current_time+B[iB]<=K:
        current_time+=B[iB]
        iB+=1
        current_value+=1
        if current_value>max_value:
            max_value=current_value
    else:
        current_time-=A[iA]
        iA-=1
        current_value-=1

print(max_value)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a_books = [int(i) for i in input().split()]
b_books = [int(i) for i in input().split()]

a = 0
b = 0
count = 0
time = 0
while True:
  if (a == n) and (b == m):
    break
  if (a == n) and (b < m):
    time += b_books[b]
    if time <= k:
      count += 1
      b += 1
      continue
    else:
      break
  if (a < n) and (b == m):
    time += a_books[a]
    if time <= k:
      count += 1
      a += 1
      continue
    else:
      break
  if (a < n) and (b < m):
    if a_books[a] < b_books[b]:
      time += a_books[a]
      if time <= k:
        count += 1
        a += 1
        continue
      else:
        break
    else:
      time += b_books[b]
      if time <= k:
        count += 1
        b += 1
        continue
      else:
        break
print(count)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a_books = [int(i) for i in input().split()]
b_books = [int(i) for i in input().split()]

a = 0
b = 0
count = 0
time = 0
while time <= k:
  if (a == n) and (b == m):
    break
  if (a == n) and (b < m):
    time += b_books[b]
    if time <= k:
      count += 1
      b += 1
  if (a < n) and (b == m):
    time += a_books[a]
    if time <= k:
      count += 1
      a += 1
  if (a < n) and (b < m):
    if a_books[a] < b_books[b]:
      time += a_books[a]
      if time <= k:
        count += 1
        a += 1
    else:
      time += b_books[b]
      if time <= k:
        count += 1
        b += 1
print(count)

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()))
    import itertools
    sum_a = list(itertools.accumulate(a))
    sum_b = list(itertools.accumulate(b))
    if sum_a[-1] + sum_b[-1] <= k:
        print(n+m)
        return
    if a[0] > k and b[0] > k:
        print(0)
        return

    for i in range(n):
        if sum_a[i] > k:
            break

    s_a = i - 1
    now_sum = 0
    if s_a >= 0:
        now_sum = sum_a[s_a]
    for i in range(m):
        if now_sum + sum_b[i] > k:
            break
    s_b = i - 1
    ans = s_a + 1 + s_b + 1
    now_sum = 0
    for a_i in range(s_a-1, -2, -1):
        for b_i in range(s_b+1,m):
            if a_i < 0:
                now_sumtime = sum_b[b_i]
            else:
                now_sumtime = sum_a[a_i] + sum_b[b_i]

            if b_i == m-1 and now_sumtime <= k:
                now_sum = a_i + m + 1
                break
            if now_sumtime > k:
                now_sum = a_i + b_i + 1
                break
        s_b = b_i-1
        ans = max(ans, now_sum)
    print(ans)

if __name__=='__main__':
    main()

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()))
    import itertools
    sum_a = list(itertools.accumulate(a))
    sum_b = list(itertools.accumulate(b))
    if sum_a[-1] + sum_b[-1] <= k:
        print(n+m)
        return
    if a[0] > k and b[0] > k:
        print(0)
        return

    for i in range(n):
        if sum_a[i] > k:
            break

    s_a = i - 1
    now_sum = 0
    if s_a >= 0:
        now_sum = sum_a[s_a]
    for i in range(m):
        if now_sum + sum_b[i] > k:
            break
    s_b = i - 1
    ans = s_a + 1 + s_b + 1
    now_sum = 0
    for a_i in range(s_a-1, -2, -1):
        for b_i in range(s_b,m):
            if a_i < 0:
                now_sumtime = sum_b[b_i]
            else:
                now_sumtime = sum_a[a_i] + sum_b[b_i]

            if b_i == m-1 and now_sumtime <= k:
                now_sum = a_i + m + 1
                break
            if now_sumtime > k:
                now_sum = a_i + b_i + 1
                break
        s_b = b_i
        ans = max(ans, now_sum)
    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()))

que1 = deque(a)
que2 = deque(b)

point = 0
count = 0
 
while 1:

    try:
        ctp1 = que1.popleft()
    except IndexError:
        que1.appendleft(float('inf'))
    try:
        ctp2 = que2.popleft()
    except IndexError:
        que2.appendleft(float('inf'))

    if ctp1 >= ctp2:
        point += ctp2
        que1.appendleft(ctp1)
        if point <= k:
            count += 1
        else:
            break

    elif ctp2 > ctp1:
        point += ctp1
        que2.appendleft(ctp2)
        if point <= k:
            count += 1
        else:
            break

print(count)

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()))
    import itertools
    sum_a = list(itertools.accumulate(a))
    sum_b = list(itertools.accumulate(b))
    if sum_a[-1] + sum_b[-1] <= k:
        print(n+m)
        return
    if a[0] > k and b[0] > k:
        print(0)
        return

    for i in range(n-1, -1, -1):
        if sum_a[i] <= k:
            break

    s_a = i
    now_sum = sum_a[s_a]
    for i in range(m):
        if now_sum + sum_b[i] > k:
            break
    s_b = i - 1
    if s_b >= 0:
        now_sum += sum_b[s_b]
    ans = s_a + 1 + s_b + 1
    now_sum = 0
    for a_i in range(s_a-1, -2, -1):
        for b_i in range(s_b,m):
            if a_i < 0:
                now_sumtime = sum_b[b_i]
            else:
                now_sumtime = sum_a[a_i] + sum_b[b_i]

            if b_i == m-1 and now_sumtime <= k:
                now_sum = a_i + m
                break
            if now_sumtime > k:
                now_sum = a_i + b_i + 1
                break
        s_b = b_i
        ans = max(ans, now_sum)
    print(ans)

if __name__=='__main__':
    main()

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()))
    import itertools
    sum_a = list(itertools.accumulate(a))
    sum_b = list(itertools.accumulate(b))
    if sum_a[-1] + sum_b[-1] <= k:
        print(n+m)
        return
    if a[0] > k and b[0] > k:
        print(0)
        return

    for i in range(n-1, -1, -1):
        if sum_a[i] <= k:
            break

    s_a = i
    now_sum = sum_a[s_a]
    for i in range(m):
        if now_sum + sum_b[i] > k:
            break
    s_b = i - 1
    if s_b >= 0:
        now_sum += sum_b[s_b]
    ans = s_a + 1 + s_b + 1
    now_sum = 0
    for a_i in range(s_a-1, -2, -1):
        for b_i in range(s_b+1,m):
            if a_i < 0:
                now_sumtime = sum_b[b_i]
            else:
                now_sumtime = sum_a[a_i] + sum_b[b_i]

            if b_i == m-1 and now_sumtime <= k:
                now_sum = a_i + m
                break
            if now_sumtime > k:
                now_sum = a_i + b_i + 1
                break
        s_b = b_i-1
        ans = max(ans, now_sum)
    print(ans)

if __name__=='__main__':
    main()