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: Runtime Error

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import accumulate
from bisect import bisect
def main():
    n, m, k = map(int, input().split())
    a = tuple(map(int, input().split()))
    b = tuple(map(int, input().split()))

    aa = tuple(accumulate(a))
    ba = tuple(accumulate(b))
    r = 0
    for i1, aae in enumerate(aa):
        if aae > k:
            break
        else:
            time_remain = k - aae
            b_num = bisect(ba, time_remain)
            if pos:
                rtmp = i1 + 1 + b_num
            else:
                rtmp = i1 + 1
            r = max(r, rtmp)
    print(r)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import deque
n,m,k = map(int,input().split())
a = deque(map(int,input().split()))
b = deque(map(int,input().split()))
time = 0
cnt = 0
while time <= k:
    if a and b:
        time += min(a.popleft(),b.popleft())
    elif a:
        time += a.popleft()
    else:
        time += b.popleft()
    if time <= k:
        cnt += 1
    else:
        break
print(cnt)

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
if len(A)>len(B):
    A += [0]*(len(A)-len(B))
elif len(B)>len(A):
    B += [0]*(len(B)-len(A))
print(A)
print(B)
time = 0
count = 0
i = 0
j = 0
goukei = 0
while time <= K:
    if A[i]>=B[j]:
        time += B[j]
        if time <= K:
            j +=1
            count += 1
    elif A[i] < B[j]:
        time += A[i]
        if time <= K:
            i += 1
            count +=1
print(count)

Submission status: Runtime Error

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
i = 0
j = 0
while time <= K:
    if A[i]>=B[j]:
        time += B[j]
        if time <= K:
            j +=1
            count +=1
    elif A[i] < B[j]:
        time += A[i]
        if time <= K:
            i +=1
            count +=1
print(count)

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
totala=0
totalb=0
cnta=0
cntb=0
for i in range(0,n-1):
 totala+=a[i]
 cnta+=1
 if totala>k:
  c.append(cnta-1)
  break
 elif i==n-1:
  c.append(cnta)
 for j in range(0,m-1):
  totalb+=b[j]
  cntb+=1
  if totala+totalb>k:
   c.append(cnta+cntb-1)
   totalb=0
   cntb=0
  elif j==m-1:
   c.append(cnta+cntb)
   totalb=0
   cntb=0
c=sorted(c,reverse=True)
print(int(c[0]))

Submission status: Runtime Error

Solution code:
import sys
import random
import bisect
from collections import deque

def cumsum(a):
    tmp = 0
    ret = []
    for i in range(len(a)):
        tmp += a[i]
        ret.append(tmp)
    return ret

x = input().split()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
n, m, k = int(x[0]), int(x[1]), int(x[2])

#n, m = 100000, 100000
#time = 100000000
#a = list(random.choices(range(10000), k=n))
#b = list(random.choices(range(10000), k=m))

a_sum, b_sum = cumsum(a), cumsum(b)

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

print (ans)

Submission status: Runtime Error

Solution code:
import sys
import random
import bisect
from collections import deque

def cumsum(a):
    tmp = 0
    ret = []
    for i in range(len(a)):
        tmp += a[i]
        ret.append(tmp)
    return ret

x = input().split()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
n, m, k = int(x[0]), int(x[1]), int(x[2])

#n, m = 100000, 100000
#time = 100000000
#a = list(random.choices(range(10000), k=n))
#b = list(random.choices(range(10000), k=m))

a_sum, b_sum = cumsum(a), cumsum(b)

ans, j = 0, m
for i in range(n + 1):
    if a_sum[i] > k:
        break
    while b[j] > k - a[i]:
        j -= 1
        ans = max(ans, i + j)

print (ans)

Submission status: Runtime Error

Solution code:
import sys
import random
import bisect
from collections import deque

def cumsum(a):
    tmp = 0
    ret = []
    for i in range(len(a)):
        tmp += a[i]
        ret.append(tmp)
    return ret

x = input().split()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
n, m, time = int(x[0]), int(x[1]), int(x[2])

#n, m = 100000, 100000
#time = 100000000
#a = list(random.choices(range(10000), k=n))
#b = list(random.choices(range(10000), k=m))

a_sum, b_sum = cumsum(a), cumsum(b)

ans, j = 0, m
for i in range(n + 1):
    if a_sum[i] > k:
        break
    while b[j] > k - a[i]:
        j -= 1
        ans = max(ans, i + j)

print (ans)

Submission status: Runtime Error

Solution code:
import sys
import random
import bisect
from collections import deque

def cumsum(a):
    tmp = 0
    ret = []
    for i in range(len(a)):
        tmp += a[i]
        ret.append(tmp)
    return ret

#x = input().split()
#a = list(map(int, input().split()))
#b = list(map(int, input().split()))
#n, m, time = int(x[0]), int(x[1]), int(x[2])

#n, m = 100000, 100000
#time = 100000000
#a = list(random.choices(range(10000), k=n))
#b = list(random.choices(range(10000), k=m))

a_sum, b_sum = cumsum(a), cumsum(b)

ans, j = 0, M
for i in range(N + 1):
    if a_sum[i] > k:
        break
    while b[j] > k - a[i]:
        j -= 1
        ans = max(ans, i + j)

print (ans)

Submission status: Runtime Error

Solution code:
import sys
import random
import bisect
from collections import deque

x = input().split()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
n, m, time = int(x[0]), int(x[1]), int(x[2])

#n, m = 100000, 100000
#time = 100000000
#a = list(random.choices(range(10000), k=n))
#b = list(random.choices(range(10000), k=m))

a_sum, b_sum = cumsum(a), cumsum(b)

a_pos = bisect.bisect_left(a_sum, time)
b_pos = bisect.bisect_left(b_sum, time)
read = 0
for i in range(a_pos):
    bpos = bisect.bisect_left(b_sum, time-a_sum[i]+.1)
    read = max(read, i+bpos+1)

print (read)

def cumsum(a):
    tmp = 0
    ret = []
    for i in range(len(a)):
        tmp += a[i]
        ret.append(tmp)
    return ret

Submission status: Runtime Error

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

a_sum = [0] * (len(As) + 1)
b_sum = [0] * (len(Bs) + 1)

for i in range(1, len(As)):
    a_sum[i] = a_sum[i-1] + As[i]

for j in range(1, len(Bs)):
    b_sum[i] = b_sum[i-1] + Bs[i]

max_book_num = 0
j = M
for i in range(N+1):
    if a_sum[i] > K:
        continue

    while b_sum[j] + a_sum[i] > K:
        j -= 1
    
    max_book_num = max(max_book_num, i + j)

        
print(max_book_num)

Submission status: Runtime Error

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

t = 0
anum = 0
for a in A:
    if K < t + a:
        break
    t += a
    anum += 1

bnum = 0
for b in B:
    if K < t + b:
        break
    t + b
    bnum += 1

ans = anum + bnum

for i in range(bnum, M):
    while K < t + B[i]:
        t -= A[anum-1]
        anum -= 1
    t += B[i]
    bnum += 1
    ans = max(ans, anum + bnum)

print(ans)

Submission status: Runtime Error

Solution code:
a = list(map(int,input().split()))
b = list(map(int,input().split()))
la = [0]
lb = [0]
mx = 0
for i in range(n): 
    la.append(la[i]+a[i])
for j in range(m):
    lb.append(lb[j]+b[j])
for l in range(len(la)):
    if la[l] > k:
        break
    cnt = l
    q = 0
    p = 0
    while la[l] + p <= k:
        q += 1
        if q == len(lb):
            cnt += len(lb)-1
            break
        p = lb[q] 
    if cnt == l:
        cnt += q - 1
    if cnt > mx:
        mx = cnt
print(mx)

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]

i = 0
j = 0
sum = 0
time = 0

while(1):
  if(A[i] <= B[j]):
    time += A[i]
    i += 1
  else:
    time += B[j]
    j += 1
    
  if time > K:
    break
  else:
    sum += time
    
print(sum)

Submission status: Runtime Error

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]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])
ans, j = 0, M
for i in range(N + 1):
  if a[i] > K:
  break
  while b[j] > K - a[i]:
    j -= 1
  ans = max(ans, i + j)
print(ans)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
a_timelist = int(input().split())
b_timelist = int(input().split())
counta = len(a_timelist)
countb = len(b_timelist)
time = 0
a, b = [0], [0]
for i in range(N):
  a.append(a[i] + a_timelist[i])
for i in range(M):
  b.append(b[i] + b_timelist[i])
ans, j = 0, M
for i in range(N+1):
  if a[i] > K:
    break
  while b[i] > K -a[i]:
    j -= 1
  ans = max(ans, i + j)
print(ans)
N, M, K = int(input().split())
a_timelist = int(input().split())
b_timelist = int(input().split())
counta = len(a_timelist)
countb = len(b_timelist)
time = 0
a, b = [0], [0]
for i in range(N):
  a.append(a[i] + a_timelist[i])
for i in range(M):
  b.append(b[i] + b_timelist[i])
ans, j = 0, M
for i in range(N+1):
  if a[i] > K:
    break
  while b[i] > K -a[i]:
    j -= 1
  ans = max(ans, i + j)
print(ans)
提出情報

Submission status: Runtime Error

Solution code:
N, M, K = map(int, (input().split()))
a_timelist = int(input().split())
b_timelist = int(input().split())
counta = len(a_timelist)
countb = len(b_timelist)
time = 0
a, b = [0], [0]
for i in range(N):
  a.append(a[i] + a_timelist[i])
for i in range(M):
  b.append(b[i] + b_timelist[i])
ans, j = 0, M
for i in range(N+1):
  if a[i] > K:
    break
  while b[i] > K -a[i]:
    j -= 1
  ans = max(ans, i + j)
print(ans)
N, M, K = int(input().split())
a_timelist = int(input().split())
b_timelist = int(input().split())
counta = len(a_timelist)
countb = len(b_timelist)
time = 0
a, b = [0], [0]
for i in range(N):
  a.append(a[i] + a_timelist[i])
for i in range(M):
  b.append(b[i] + b_timelist[i])
ans, j = 0, M
for i in range(N+1):
  if a[i] > K:
    break
  while b[i] > K -a[i]:
    j -= 1
  ans = max(ans, i + j)
print(ans)

Submission status: Runtime Error

Solution code:
N, M, K = int(input().split())
a_timelist = int(input().split())
b_timelist = int(input().split())
counta = len(a_timelist)
countb = len(b_timelist)
time = 0
a, b = [0], [0]
for i in range(N):
  a.append(a[i] + a_timelist[i])
for i in range(M):
  b.append(b[i] + b_timelist[i])
ans, j = 0, M
for i in range(N+1):
  if a[i] > K:
    break
  while b[i] > K -a[i]:
    j -= 1
  ans = max(ans, i + j)
print(ans)

Submission status: Runtime Error

Solution code:
N, M, K = input().split()
a_timelist = input().split()
b_timelist = input().split()
N, M, K = int(N), int(M), int(K)
a_timelist = [int(x) for x in a_timelist]
b_timelist = [int(x) for x in b_timelist]
counta = len(a_timelist)
countb = len(b_timelist)
counter = 0
time = 0
if a_timelist[0] > K and b_timelist[0] > K:
  print(0)
  exit()
while time <= K:
  if a_timelist == [] and b_timelist == []:
    print(counta + countb)
    exit()
  if (b_timelist == [] and a_timelist != []) or (a_timelist[0] >= b_timelist[0]):
    time += a_timelist[0]
    counter += 1
    del a_timelist[0]
  elif (a_timelist == [] and b_timelist != []) or (a_timelist[0] <= b_timelist[0]):
    time += b_timelist[0]
    counter += 1
    del b_timelist[0]
print(counter)

Submission status: Runtime Error

Solution code:
n,m,k = map(int, input().split())
a_list = [int(x.strip()) for x in input().split()]
b_list = [int(y.strip()) for y in input().split()]
a_top,b_top,time,ans = 0,0,0,0
next_tbl = 'a'
for i in range(n+m):
  if len(a_list) == 0:
    next_tbl = 'b'
  elif len(b_list) == 0:
    next_tbl = 'a'
  else:
    a_top = a_list[0]
    b_top = b_list[0]
    if time == k or min(a_top,b_top)+time > k:
      break
    elif a_top == b_top:
      j_max = min(len(a_top),len(b_top))
      a_ch,b_ch = 0
      for j in range(j_max):
        a_ch += a_list[i]
        b_ch += b_list[i]
        if a_ch != b_ch and a_ch < b_ch:
          next_tbl = 'a'
          break
        elif a_ch != b_ch and a_ch > b_ch:
          next_tbl = 'b'
          break
    elif a_top < b_top:
      next_tbl = 'a'
    else:
      next_tbl = 'b'
  if next_tbl == 'a':
    time += a_top
    del a_list[0]
    ans += 1
  else:
    time += b_top
    del b_list[0]
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
from bisect import bisect
from collections import deque

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

for i in range(1, len(A)+1):
    A[i] += A[i-1]
for i in range(1, len(B)+1):
    B[i] += B[i-1]

indexB = len(B) - 1
results = [0]
for i in range(len(A)):
    time = A[i]
    if time > K:
        break
    enable_for_b = K - time
    results.append(i + bisect(B, enable_for_b))

print(max(results))

Submission status: Runtime Error

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

for i in range(1, len(A)):
    A[i] += A[i-1]
for i in range(1, len(B)):
    B[i] += B[i-1]

indexB = len(B) - 1
results = []
for i in range(len(A)):
    time = A[i]
    if time > K:
        break
    while(indexB >= 0 and time + B[indexB] > K):
        indexB -= 1
    results.append(i+1 + indexB+1)

print(max(results))

Submission status: Runtime Error

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

for i in range(1, len(A)):
    A[i] += A[i-1]
for i in range(1, len(B)):
    B[i] += B[i-1]

indexB = len(B)
best = 0
for i in range(len(A)):
    time = A[i]
    if time > K:
        break
    while(indexB >= 0 and time + B[indexB] > K):
        indexB -= 1
    count = i+1 + indexB+1
    if (best < count):
        best = count
print(best)

Submission status: Runtime Error

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

for i in range(1, len(A)):
    A[i] += A[i-1]
for i in range(1, len(B)):
    B[i] += B[i-1]

indexB = len(B) - 1
best = 0
for i in range(len(A)):
    time = A[i]
    if time > K:
        break
    else:
        while(indexB >= 0 and time + B[indexB] > K):
            indexB -= 1
        count = i+1 + indexB+1
        if indexB < len(B)-1:
        indexB += 1
    if (best < count):
        best = count
print(best)

Submission status: Runtime Error

Solution code:
info = list(map(int, input().split()))
N = info[0]
M = info[1]
K = info[2]
L = max(N, M)

A_books = list(map(int, input().split()))
B_books = list(map(int, input().split()))


A_SUM = [A_books[0]]
B_SUM = [B_books[0]]
max_count = []
i = 1
while i < N:
    A_SUM.append(A_books[i] + A_SUM[i - 1])
    i += 1
j = 1
while j < M:
    B_SUM.append(B_books[j] + B_SUM[j - 1])
    j += 1

for k in range(N):
    for l in range(M):
        if (A_SUM[k] + B_SUM[l]) <= K:
            max_count.append(k + l)


print(max(max_count)+2)

Submission status: Runtime Error

Solution code:
info = list(map(int, input().split()))
N = info[0]
M = info[1]
K = info[2]
L = max(N, M)

A_books = list(map(int, input().split()))
B_books = list(map(int, input().split()))


A_SUM = [A_books[0]]
B_SUM = [B_books[0]]
max_count = []
i = 1
while i < N:
    A_SUM.append(A_books[i] + A_SUM[i - 1])
    i += 1
j = 1
while j < M:
    B_SUM.append(B_books[j] + B_SUM[j - 1])
    j += 1

for k in range(N):
    for l in range(M):
        if (A_SUM[k] + B_SUM[l]) <= K:
            max_count.append(k + l)


print(max(max_count + 2))

Submission status: Runtime Error

Solution code:
info = list(map(int, input().split()))
N = info[0]
M = info[1]
K = info[2]
L = max(N, M)

A_books = list(map(int, input().split()))
B_books = list(map(int, input().split()))


if len(A_books) < M:
    for i in range(M - N):
        A_books.append(float("inf"))

if len(B_books) < N:
    for i in range(N - M):
        B_books.append(float("inf"))


min = 0
count = 0

def select_book(A_books, B_books, i, j):
    global min
    global count

    if (i < L) and (j < L):
        if A_books[i] < B_books[j]:
            min += A_books[i]
            if min <= K:
                count += 1
                select_book(A_books, B_books, i + 1, j)
        else:
            min += B_books[j]
            if min <= K:
                count += 1
                select_book(A_books, B_books, i, j + 1)

select_book(A_books, B_books, 0, 0)
print(count)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#include<math.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18 
int main(){
    int n, m , k ;
    cin >> n >> m >> k ;
    vector<int> a (n);
    vector<int> b (m);
    rep(i, n) cin >> a[i] ;
    rep(i, m) cin >> b[i] ;
    ll t = 0 ;
    rep(i, m) t+= b[i] ;
    int j = m ;
    int ans = 0 ;
    rep(i, n+1){
        while(j > 0 && t > k){
            --j ;
            t -= b[j] ;
        }
        if (t > k) break ;
        ans = max(ans, i + j) ;
        if(i == n) break ;
        t += a[i] ;
    }
    cout << ans << endl ;
}

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#include<math.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18 
int main(){
    int n, m , k ;
    vector<int> a (n);
    vector<int> b (m);
    rep(i, n) cin >> a[i] ;
    rep(i, m) cin >> b[i] ;
    ll t = 0 ;
    rep(i, m) t+= b[i] ;
    int j = m ;
    int ans = 0 ;
    rep(i, n+1){
        while(j > 0 && t > k){
            --j ;
            t -= b[j] ;
        }
        if (t > k) break ;
        ans = max(ans, i + j) ;
        if(i == n) break ;
        t += a[i] ;
    }
    cout << ans << endl ;
}

Submission status: Runtime Error

Solution code:
N,M,K = map(int,input().split())
t = 0
c = 0
n_list = list(map(int,input().split()))
m_list = list(map(int,input().split()))

while N+M >= c and t < K:
    if n_list[0] >= m_list[0]:
        t += m_list.pop(0)
        c += 1
    else:
        t += n_list.pop(0)
        c += 1

if t > K:        
    print(c-1)
else:
    print(c)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
a_books = list(map(int, input().split()))
b_books = list(map(int, input().split()))
a_time = 0
b_time = 0
a_times = [0 for _ in range(N+1)]
b_times = [0 for _ in range(M+1)]
for i, a in enumerate(a_books):
  a_time += a
  a_times[i+1] = a_time
  
for i, b in enumerate(b_books):
  b_time += b
  b_times[i+1] = b_time
  
result = 0
l = 0
for i in range(N+1):
  if l == M:
    break
  while(True):
    if a_times[N-i] + b_times[l] <= K:
      result = max(result, N-i+l)
      l += 1
    else:
      break
print(result)

Submission status: Runtime Error

Solution code:
n,m,k = list(map(int, input().split()))
a_list = np.array(input().split()).astype(int)
b_list = np.array(input().split()).astype(int)
ans_list=[]
for i in range(n):
    for l in range(m):
        if sum(a_list[:i]) + sum(b_list[:l]) <= k:
            ans_list.append(i+l)
            
ans_list.sort()
print(ans_list[-1])

Submission status: Runtime Error

Solution code:
 
a = [0]
b = [0]
for i in range(n):
  a.append(a[i]+A[i])
for j in range(m):
  b.append(b[j]+B[j])
#print(a,b)
 
ans = 0
j = m
for i in range(n+1):
  if a[i] > k:
    break
  while (k - a[i]) < b[j]:
    j -= 1
    if j == -1:
      break
  
  ans = max(ans, i+j)
     
print(ans)

Submission status: Runtime Error

Solution code:
n, m,k = list(map(int, input().split()))
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
count = 0
for i in range(n + m):
    #print(k)
    if a_list[0] >= b_list[0] and len(a_list) >= 1:
        k -= a_list.pop(0)
    else:
        k -= b_list.pop(0)
        
    if k > 0:
        count += 1
    else:
        break
        
print(count+1)

Submission status: Runtime Error

Solution code:
n, m,k = list(map(int, input().split()))
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
count = 0
for i in range(n + m):
    print(k)
    if a_list[0] >= b_list[0] and len(a_list) >= 1:
        k -= a_list.pop(0)
    else:
        k -= b_list.pop(0)
        
    if k > 0:
        count += 1
    else:
        break
        
print(count+1)

Submission status: Runtime Error

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

ans = 0
total = 0
while total <= k:
  if len(a) != 0 and len(b) != 0:
    if a[0] < b[0]:
      total += a.pop(0)
    else:
      total += b.pop(0)
    ans += 1
  elif len(a) == 0:
    total += b.pop(0)
    ans += 1
  elif len(b) == 0:
    total += a.pop(0)
    ans += 1
  else:
    break
if total > k:
  print(ans - 1)
else:
  print(ans)

Submission status: Runtime Error

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

ans = 0
total = 0
while total <= k:
  if a[0] < b[0]:
    total += a.pop(0)
  else:
    total += b.pop(0)
  ans += 1

if total > k:
  print(ans - 1)
else:
  print(ans)

Submission status: Runtime Error

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

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

ans = 0
temp_a = {}
temp_b = {}

for i_a in range(n+1):
  if sum(a[0:i_a]) > k:
    break
  temp_a[i_a] = sum(a[0:i_a])
for i_b in range(m+1):
  if sum(b[0:i_b]) > k:
    break
  temp_b[i_b] = sum(b[0:i_b])
  
temp_a = sorted(temp_a.items(), key=lambda x:x[1], reverse=True)
temp_b = sorted(temp_b.items(), key=lambda x:x[1], reverse=True)
ans = {}

if len(item_a) > len(item_b):
  item_a, item_b = item_b, item_a

for item_a in temp_a:
  for item_b in temp_b:
    if item_a[1] + item_b[1] > k:
      continue
    else:
      ans[len(ans)] = item_a[0] + item_b[0]
      break

ans = max(ans.values())
print(ans)

Submission status: Runtime Error

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

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

a.extend(b).sort()
add = 0

for item in a:
  if add >= k:
    break
  add += item
  
print(add)

Submission status: Runtime Error

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

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

a = a.extend(b).sort()
add = 0

for item in a:
  if add >= k:
    break
  add += item
  
print(add)

Submission status: Runtime Error

Solution code:
import bisect

#入力
N,M,K = (int(x) for x in input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

#A総和のリストの作成
A_sum = [0]*N
A_sum[0]=A[0]
i = 1
while True:
  A_sum[i] = A_sum[i-1]+A[i]
  i+=1
  if i==N-1:
    break

#B総和のリストの作成
B_sum = [0]*M
B_sum[0]=B[0]
i = 1
while True:
  B_sum[i] = B_sum[i-1]+B[i]
  i+=1
  if i==M-1:
    break

SUM = []

#計算の開始
for j in range(N):
  remain = K-A_sum[j]
  if remain>=0:
    B_number=bisect.bisect(B_sum,remain)
    if B_number==0:
      SUM.append(j+1)
    else:
      SUM.append(j+1+B_number)
  else:
    SUM.append(0)

print(max(SUM))

Submission status: Runtime Error

Solution code:
import bisect

#入力
N,M,K = (int(x) for x in input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

#A総和のリストの作成
A_sum = [0]*N
A_sum[0]=A[0]
i = 1
while True:
  print(i)
  A_sum[i] = A_sum[i-1]+A[i]
  i+=1
  if i==N-1:
    break

#B総和のリストの作成
B_sum = [0]*M
B_sum[0]=B[0]
i = 1
while True:
  B_sum[i] = B_sum[i-1]+B[i]
  i+=1
  if i==M-1:
    break

SUM = []

#計算の開始
for j in range(N):
  remain = K-A_sum[j]
  if remain>=0:
    B_number=bisect.bisect(B_sum,remain)
    if B_number==0:
      SUM.append(j+1)
    else:
      SUM.append(j+1+B_number)
  else:
    SUM.append(0)

print(max(SUM))

Submission status: Runtime Error

Solution code:
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]
A.insert(0,0)
B.insert(0,0)

j = m
ans = 0
for i in range(m):
    if A[i] > k:
        break
    
    while B[j] > k-A[i]:
        j -= 1
    ans = max(ans, i+j)

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
N, M, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
time_list = a + b
time_lists = np.sort(time_lists)
cum_times = np.cumsum(time_lists)
print(int((cum_times <= K).sum()))

Submission status: Runtime Error

Solution code:
import numpy as np
N, M, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
time_lists = np.sort(time_lists)
cum_times = np.cumsum(time_lists)
print(int((cum_times <= K).sum()))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

count=0
k=0
i=0
j=0
while k<=K:
  if A[i]<=B[j]:
    k+=A[i]
    i+=1
    count+=1
  else:
    k+=B[j]
    j+=1
    count+=1
    
print(count-1)

Submission status: Runtime Error

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A.sort()
B.sort()
count=0
k=0
i=0
j=0
while k<=K:
  if i<N and A[i]<=B[j]:
    k+=A[i]
    i+=1
    #print(k)
    count+=1
  elif j<M:
    k+=B[j]
    j+=1
    #print(k)
    count+=1
  elif j>=M and i>=N:
    count+=1
    break
print(count-1)

Submission status: Runtime Error

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A.sort()
B.sort()
count=0
k=0
i=0
j=0
while k<=K:
  if i<N and A[i]<=B[j]:
    k+=A[i]
    i+=1
    #print(k)
    count+=1
  elif j<M:
    k+=B[j]
    j+=1
    #print(k)
    count+=1
  else:
    count+=1
    break
print(count-1)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A.sort()
B.sort()
count=0
k=0
i=0
j=0
while k<=K:
  if A[i]<=B[j]:
    k+=A[i]
    i+=1
    count+=1
  else:
    k+=B[j]
    j+=1
    count+=1
    
print(count-1)

Submission status: Runtime Error

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A.sort()
B.sort()
count=0
k=0
i=0
j=0
while k<=K:
  if A[i]<=B[j]:
    k+=A[i]
    i+=1
    count+=1
  else:
    k+=B[j]
    j+=1
    count+=1
    
print(count)

Submission status: Runtime Error

Solution code:
n, m, k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
for i in range(n+1):
  if a[i] > k:
    continue
  for j in range(m+1):
    if b[j] > k:
    continue
    time = sum(a[:i]) + sum(b[:j])
    if time <= k and i + j > ans:
      ans = i + j
print(ans)

Submission status: Runtime Error

Solution code:
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect

def solve():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ruia, ruib = [0], [0]
    for i in range(n): ruia.append(a[i]+ruia[i])
    for i in range(m): ruib.append(b[i]+ruib[i])
    ans = 0
    j = m
    for i in range(n+1):
        if ruia[i] > k:
            break
        while(k > ruia[i]+ruib[j]):
            j -= 1
        ans = max(ans, i+j)
    print(ans)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Runtime Error

Solution code:
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect

def solve():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ruia, ruib = [0], [0]
    for i in range(n): ruia.append(a[i]+ruia[i])
    for i in range(m): ruib.append(b[i]+ruib[i])
    ans = 0
    j = m
    for i in range(n+1):
        if ruia[i] > k:
            break
        while(k > ruia[i]+ruib[j]):
            j -= 1
            ans = max(ans, i+j)
    print(ans)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Runtime Error

Solution code:
N,M,K=map(int,input().split())
import numpy as np
a=np.array(list(map(int,input().split())))
b=np.array(list(map(int,input().split())))
a_s=a.cumsum()
b_s=b.cumsum()
an=0
ans=0
while an<N and a_s[an]<=K:
    bn=0
  while bn<M and a_s[an]+b_s[bn]<=K:
    bn+=1
  if an+bn+1>ans:
    ans=an+bn+1
  an+=1
print(ans)