Problem:


Score : 300 points

Problem Statement

We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.

It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).

Consider the following action:

Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.

How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

Output

Print an integer representing the maximum number of books that can be read.

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

In this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd books from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st, 2-nd, 3-rd, 4-th books from the top on Desk B, respectively.

We can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.

Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.

Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.

Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000

Sample Output 3

0

Watch out for integer overflows.



Sample input:
3 4 240
60 90 120
80 150 80 150


Sample output:
3

Submission status: Wrong Answer

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

for i in range(1,n):
  a[i] += a[i-1]
for i in range(1,m):
  b[i] += b[i-1]
    
ans = 0
for i in range(n, 0, -1):
  p = 0
  q = 0
  if a[i-1] <= k:
    p = a[i-1]
    q = i
  for j in range(m, 0, -1):
    if p + b[j-1] <= k:
      ans = max(ans, q + j)
    
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N, M, K = map(int, input().split())
    A = [int(a) for a in input().split()]
    B = [int(b) for b in input().split()]
    Bsum = sum(B)
    ans = Asum = 0
    idx_b = len(B) - 1

    if sum(B) <= K:
        ans = len(B)

    for i in range(N):
        Asum += A[i]

        for j in range(idx_b + 1):
            if Asum + Bsum > K:
                if idx_b >= 0:
                    Bsum -= B[idx_b]
                    idx_b -= 1
                else:
                    break
            else:
                break

        if Asum + Bsum <= K:
            ans = max(ans, (i + 1) + (idx_b + 1))

    print(ans)
 
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AS=[0]
BS=[0]
r=0
for i in A:
  AS.append(i+AS[-1])
for i in B:
  BS.append(i+BS[-1])
p=n+m+2
f=1
for i in range(1,n+1):
  for j in range(f,m+1):
    if AS[-i]+BS[-j]<=k:
      r=max(r,p-i-j)
      f=j
print(r)

Submission status: Wrong Answer

Solution code:
o,p,q=map(int,input().split())
o=int(o)
p=int(p)
q=int(q)
A = input().split()
B = input().split()
a = [int(s) for s in A]
b = [int(s) for s in B]
a[len(a):len(a)]=b
c=sorted(a)
w=len(c)
www=0
for i in range(len(c)):
    www+=c[i]
    
  
    if www>=q:        
        if www==q:
            i+=1
            
        break
    else:
        continue

print(i)

Submission status: Wrong Answer

Solution code:
from collections import deque

# ACできなかったコード(貪欲法を使用)
def main_NoAC():
    N, M, K = map(int, input().split())
    A = deque([int(a) for a in input().split()])
    B = deque([int(b) for b in input().split()])
    inf = 10**10
    A.append(inf)
    B.append(inf)

    ans = tot = 0

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

        if a < b:
            if tot + a <= K:
                ans += 1
                tot += A.popleft()

        elif a > b:
            if tot + b <= K:
                ans += 1
                tot += B.popleft()

        else:
            if tot + a <= K:
                ans += 1
                tot += A.popleft()
                
    print(ans)

# 解きなおしたコード
def main():
    N, M, K = map(int, input().split())
    A = [int(a) for a in input().split()]
    B = [int(b) for b in input().split()]
    Bsum = sum(B)
    ans = Asum = 0
    idx_b = len(B) - 1

    for i in range(N):
        Asum += A[i]

        for j in range(idx_b + 1):
            if Asum + Bsum > K:
                if idx_b >= 0:
                    Bsum -= B[idx_b]
                    idx_b -= 1
                else:
                    break
            else:
                break

        if Asum + Bsum <= K:
            ans = max(ans, (i + 1) + (idx_b + 1))

    print(ans)
 
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N, M, K = map(int, input().split())
    A = [int(a) for a in input().split()]
    B = [int(b) for b in input().split()]
    Bsum = sum(B)
    ans = Asum = 0
    idx_b = len(B) - 1

    for i in range(N):
        Asum += A[i]

        for j in range(len(B)):
            if Asum + Bsum > K:
                if idx_b >= 0:
                    Bsum -= B[idx_b]
                    idx_b -= 1
                else:
                    break
            else:
                break

        if Asum + Bsum <= K:
            ans = max(ans, i + 1 + idx_b + 1)

    print(ans)
 
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

for i in range(m):
    if i == 0 :
        bb.append(b[0])
    else:
        bb.append(bb[i-1]+b[i])
ans = 0
for i in range(n):
    x = k - aa[i]
    for j in range(m):
        if bb[0] > x:
            break
        if bb[0] == x:
            ans = i+1
            break
        if bb[j] > x:
            ans = i + j+1
            break
        if j == m-1:
            ans = i+j+2
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()))

ans = 0
ai = 0
bi = 0
for i in range(n+m):
  if ai == n:
    if(ans + b[bi] <= k):
      ans += b[bi]
      bi += 1
    else:
      break
  elif bi == m:
    if(ans + a[ai] <= k):
      ans += a[ai]
      ai += 1
    else:
      break
  else:
    if a[ai] > b[bi]:
      if(ans + b[bi] <= k):
        ans += b[bi]
        bi += 1
      else:
        break
    else:
      if(ans + a[ai] <= k):
        ans += a[ai]
        ai += 1
      else:
        break
print(ai + bi)

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()))
aa=[]
bb=[]

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

for i in range(m):
    if i == 0 :
        bb.append(b[0])
    else:
        bb.append(bb[i-1]+b[i])
ans = 0
for i in range(n):
    x = k - aa[i]
    for j in range(m):
        if bb[0] > x:
            break
        if bb[0] == x:
            ans = i+1
            break
        if bb[j] > x:
            ans = i + j+1
            break
        if j == m:
            ans = i+j+2
            
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
arr_a = list(map(int, input().split()))
arr_b = list(map(int, input().split()))
ans_a =0
ans_b =0
time =0

for i in range(N):
    if time + arr_a[i] > K:
        break
    else:
        ans_a +=1
        time += arr_a[i]
for i in range(M):
    if time + arr_b[i] > K:
        break
    else:
        ans_b +=1
        time += arr_b[i]

ans = ans_a + ans_b
ans_koho = ans_a + ans_b
cnt_b = ans_b

for i in range(ans_a):
    ans_koho -= 1
    time -= arr_a[-1*(i+1)]

    while True:
        if cnt_b == M:
            break
        elif time + arr_b[cnt_b] > K:
            break
        else:
            time += arr_b[cnt_b]
            cnt_b += 1
            ans_koho += 1
    ans = max(ans, ans_koho)

print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right

def cumsum(a):
    res = []
    res.append(a[0])
    for i in range(1, len(a)):
        res.append(res[i - 1] + a[i])
    return res

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ca = cumsum(a)
cb = cumsum(b)

ans = 0
x = bisect_right(ca, k)
for i in range(x):
    y = bisect_right(cb, k - ca[i])
    ans = max(ans, x + y)

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
a_count = 0
b_count = 0
for i in range(n+m):
    if a[a_count] < b[b_count]:
        time += a[a_count]
        if time > k:
            print(a_count+b_count)
            exit()
        if (a_count+1) == len(a):
            a[a_count] = float("inf")
        else:
            a_count += 1
    else:
        time += b[b_count]
        if time > k:
            print(a_count+b_count)
            exit()
        if (b_count+1) == len(b):
            b[b_count] = float("inf")
        else:
            b_count += 1

print(a_count+b_count+2)

Submission status: Wrong Answer

Solution code:
N, M, K = map(int, input().split())
arr_a = list(map(int, input().split()))
arr_b = list(map(int, input().split()))
ans_a =0
ans_b =0
time =0

for i in range(N):
    if time + arr_a[i] > K:
        break
    else:
        ans_a +=1
        time += arr_a[i]
for i in range(M):
    if time + arr_b[i] > K:
        break
    else:
        ans_b +=1
        time += arr_b[i]

ans = ans_a + ans_b
ans_koho = ans_a + ans_b
cnt_b = ans_b

for i in range(ans_a):
    ans_koho -= 1
    time -= arr_a[-1*(i+1)]

    while True:
        if cnt_b == M:
            break
        elif time + arr_b[cnt_b] > K:
            break
        else:
            cnt_b += 1
            ans_koho += 1
    ans = max(ans, ans_koho)

print(ans)

Submission status: Wrong Answer

Solution code:
import copy
L = list(map(int, input().split())) # N, M, K=map(int,input().split())
N=L[0]
M=L[1]
K=L[2]
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = 0
b = 0
p=N
q=M
for i in range(N):
    a=a+A[i]
    if a>K:
        a=a-A[i]
        p=i
        break
if a<K:
    X=K-a
    for j in range(M):
        b=b+B[j]
        if b>X:
            b=b-B[j]
            q=j
            break
c=a+b
count=p+q
F=[p+q]
u=0
for i in range(p):
    u=0
    c=c-A[p-i-1]
    count=count-1
    for j in range(M-q):
        c=c+B[q+j]
        if K<c:
            q=q+j
            count=count+j
            c=c-B[q]
            F.append(copy.copy(count))
            u=1
            break
    if u==0:
        F.append(copy.copy(count+M-q))
        break
print(max(F))

Submission status: Wrong Answer

Solution code:
import copy
L = list(map(int, input().split())) # N, M, K=map(int,input().split())
N=L[0]
M=L[1]
K=L[2]
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = 0
b = 0
p=N
q=M
for i in range(N):
    a=a+A[i]
    if a>K:
        a=a-A[i]
        p=i
        break
if a<K:
    X=K-a
    for j in range(M):
        b=b+B[j]
        if b>X:
            b=b-B[j]
            q=j
            break
c=a+b
count=p+q
F=[p+q]
u=0
for i in range(p):
    u=0
    c=c-A[p-i-1]
    count=count-1
    for j in range(M-q):
        c=c+B[q+j]
        if K<c:
            q=q+j
            count=count+j
            c=c-B[q]
            F.append(copy.copy(count))
            u=1
            break
    if u==0:
        F.append(copy.copy(count))
        break
print(max(F))

Submission status: Wrong Answer

Solution code:
import copy
L = list(map(int, input().split())) # N, M, K=map(int,input().split())
N=L[0]
M=L[1]
K=L[2]
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = 0
b = 0
p=N
q=M
for i in range(N):
    a=a+A[i]
    if a>K:
        a=a-A[i]
        p=i
        break
if a<K:
    X=K-a
    for j in range(M):
        b=b+B[j]
        if b>X:
            b=b-B[j]
            q=j
            break
c=a+b
count=p+q
F=[p+q]
for i in range(p):
    c=c-A[p-i-1]
    count=count-1
    for j in range(M-q):
        c=c+B[q+j]
        if K<c:
            count=count+j
            q=q+j
            c=c-B[q]
            F.append(copy.copy(count))
            break
print(max(F))

Submission status: Wrong Answer

Solution code:
import copy
L = list(map(int, input().split())) # N, M, K=map(int,input().split())
N=L[0]
M=L[1]
K=L[2]
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = 0
b = 0
p=N
q=M
for i in range(N):
    a=a+A[i]
    if a>K:
        a=a-A[i]
        p=i
        break
if a<K:
    X=K-a
    for j in range(M):
        b=b+B[j]
        if b>X:
            b=b-B[j]
            q=j
            break
c=a+b
count=p+q
F=[p+q]
for i in range(p):
    c=c-A[p-i-1]
    count=count-1
    for j in range(M-q):
        c=c-B[q+j]
        if K<c:
            count=count+j
            q=q+j
            c=c+B[q]
            F.append(copy.copy(count))
            break
print(max(F))

Submission status: Wrong Answer

Solution code:
import copy
L = list(map(int, input().split())) # N, M, K=map(int,input().split())
N=L[0]
M=L[1]
K=L[2]
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = 0
b = 0
p=N
q=M
for i in range(N):
    a=a+A[i]
    if a>K:
        a=a-A[i]
        p=i
        break
if a<K:
    X=K-a
    for j in range(M):
        b=b+B[j]
        if b>X:
            b=b-B[j]
            q=j
            break
c=a+b
count=p+q
F=[p+q]
for i in range(p):
    c=c-A[p-i-1]
    count=count-1
    for j in range(M-q):
        c=c-B[q+j]
        if K<c:
            count=count+j
            q=q+j
            S=S+B[q]
            F.append(copy.copy(count))
            break
print(max(F))

Submission status: Wrong Answer

Solution code:
import copy
L = list(map(int, input().split())) # N, M, K=map(int,input().split())
N=L[0]
M=L[1]
K=L[2]
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = 0
b = 0
p=N
q=M
for i in range(N):
    a=a+A[i]
    if a>K:
        a=a-A[i]
        p=i
        break
if a<K:
    X=K-a
    for j in range(M):
        b=b+B[j]
        if b>X:
            b=b-B[j]
            q=j
            break
c=a+b
count=p+q
F=[p+q]
for i in range(p):
    c=c-A[p-i-1]
    S=K-c
    count=count-1
    for j in range(M-q):
        S=S-B[q+j]
        if S<0:
            count=count+j
            q=q+j
            S=S+B[q]
            F.append(copy.copy(count))
            break
print(max(F))

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

cnt=0
i=0
A=0
B=0
while i<n:
    cnt+=a[i]
    i+=1
    if cnt>k:
        A=i-1
        break
    else:
        A=n
i=0
cnt=0
while i<m:
    cnt+=b[i]
    i+=1
    if cnt>k:
        B=i-1
        break
    else:
        B=m

ans=0
for i in range(1,A+2):
    for j in range(1,B+2):
        if sum(a[:i])+sum(b[:j])<k:
            ans=max(ans,i+j)

print(ans)

Submission status: Wrong Answer

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

# C - Tsundoku
def get_books(n):
	from collections import deque
	que = deque()
	
	arr = input().split()
	
	for a in arr:
		que.append(int(a))
	
	return que


def select_next_book(a, b):
	if len(a) > 0:
		next_a = a.popleft()
	else:
		return 'b'
	
	if len(b) > 0:
		next_b = b.popleft()
	else:
		return 'a'
	
	if next_a < next_b:
		desk_name = 'a'
	else:
		desk_name = 'b'

	a.appendleft(next_a)
	b.appendleft(next_b)
	return desk_name


n, m, k = map(int, input().split())
a = get_books(n)
b = get_books(m)

a_first = a.popleft()
b_first = b.popleft()
total = 0
ans = 0

while True:
	desk_name = ''
	
	if a_first == -1 and b_first == -1:
		break
	elif a_first == -1:
		next = b_first
		desk_name = 'b'
	elif b_first == -1:
		next = a_first
		desk_name = 'a'
	elif a_first < b_first:
		next = a_first
		desk_name = 'a'
	elif b_first < a_first:
		next = b_first
		desk_name = 'b'
	else:
		if select_next_book(a, b) == 'a':
			next = a_first
			desk_name = 'a'
		else:
			next = b_first
			desk_name = 'b'
			
	if desk_name == 'a':
		if len(a) > 0:
			a_first = a.popleft()
		else:
			a_first = -1
	else:
		if len(b) > 0:
			b_first = b.popleft()
		else:
			b_first = -1
	
	#print(next)
	#print(total + next)
	#print(ans + 1)
	
	if total + next <= k:
		total += next
		ans += 1
	else:
		break

print(ans)

Submission status: Wrong Answer

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

# C - Tsundoku
def get_books(n):
	from collections import deque
	que = deque()
	
	arr = input().split()
	
	for a in arr:
		que.append(int(a))
	
	return que


def select_next_book(original_a, original_b):
	import copy
	a = copy.deepcopy(original_a)
	b = copy.deepcopy(original_b)
	
	if len(a) > 0:
		next_a = a.popleft()
	else:
		return 'b'
	
	if len(b) > 0:
		next_b = b.popleft()
	else:
		return 'a'
	
	if next_a < next_b:
		return 'a'
	else:
		return 'b'


n, m, k = map(int, input().split())
a = get_books(n)
b = get_books(m)

a_first = a.popleft()
b_first = b.popleft()
total = 0
ans = 0

while True:
	desk_name = ''
	
	if a_first == -1 and b_first == -1:
		break
	elif a_first == -1:
		next = b_first
		desk_name = 'b'
	elif b_first == -1:
		next = a_first
		desk_name = 'a'
	elif a_first < b_first:
		next = a_first
		desk_name = 'a'
	elif b_first < a_first:
		next = b_first
		desk_name = 'b'
	else:
		if select_next_book(a, b) == 'a':
			next = a_first
			desk_name = 'a'
		else:
			next = b_first
			desk_name = 'b'
			
	if desk_name == 'a':
		if len(a) > 0:
			a_first = a.popleft()
		else:
			a_first = -1
	else:
		if len(b) > 0:
			b_first = b.popleft()
		else:
			b_first = -1
	
	#print(next)
	#print(total + next)
	#print(ans + 1)
	
	if total + next <= k:
		total += next
		ans += 1
	else:
		break

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()))
ans = 0
i = 1
if a[0] > k and b[0] > k:
  print(0)
  sys.exit()
while i <= n:
  time = 0
  count = 0
  for z in range(i):
    time += a[z]
  if time > k:
    count = i-1
  else:
    count += i
    for j in range(m):
      if time < k:
        time += b[j]
        if time <= k:
          count += 1
      else:
        break
  if ans < count:
    ans = count
  i += 1
print(ans)

Submission status: Wrong Answer

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

# C - Tsundoku
def get_books(n):
	from collections import deque
	que = deque()
	
	arr = input().split()
	
	for a in arr:
		que.append(int(a))
	
	return que


def pop_book(que):
	if len(que) > 0:
		que.pop()



n, m, k = map(int, input().split())
a = get_books(n)
b = get_books(m)

a_first = a.popleft()
b_first = b.popleft()
total = 0
ans = 0

while True:
	if a_first == -1 and b_first == -1:
		break
	elif a_first == -1:
		next = b_first
	elif b_first == -1:
		next = a_first
	elif a_first < b_first:
		next = a_first
	else:
		next = b_first
		
	if a_first == next:
		if len(a) > 0:
			a_first = a.popleft()
		else:
			a_first = -1
	
	if b_first == next:
		if len(b) > 0:
			b_first = b.popleft()
		else:
			b_first = -1
	
	if total + next <= k:
		total += next
		ans += 1
	else:
		break

print(ans)

Submission status: Wrong Answer

Solution code:
import math
import sys
import itertools
from math import gcd
from math import sqrt
from sys import stdin
def input() : return stdin.readline().rstrip()
def mips():
    return map(int,input().split())
def ii():
    return int(input())
sys.setrecursionlimit(10**9)
#test 2 WA
N,M,K = mips()
A = [i for i in mips()]
B = [i for i in mips()]
# N,M <= 200000
ans = 0
clock = K
while (A != [] and B != []):
    if clock-min(A[0],B[0]) < 0:
        break
    else:
        ans += 1
        clock -= min(A[0],B[0])
        if A[0] <= B[0]:
            A.remove(A[0])
        else:
            B.remove(B[0])
if A == []:
    while True:
        if B!=[] and clock-B[0] >= 0:
            ans += 1
            clock -= B[0]
            B.remove(B[0])
        break
if A != []:
    while True:
        if A != [] and clock - A[0] >= 0:
            ans += 1
            clock -= A[0]
            A.remove(A[0])
        break
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

def main():
    n, m, k = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    a = A[0]
    A2 = [a]
    b = B[0]
    B2 = [b]
    for i in range(1, n):
        a += A[i]
        A2.append(a)

    for i in range(1, m):
        b += B[i]
        B2.append(b)
    max = -2
    for ia, aa in enumerate(A2):
        for ib, bb in enumerate(B2):
            if aa + bb > k:
                break
            if ia + ib > max:

                max = ia+ib
    print(max + 2)

    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,M,K=nm()
INF=10**18
A=nl()
B=nl()
A.append(INF)
B.append(INF)

a_c=0
b_c=0
asum=0
for i in range(M+1):
    asum=asum+A[i]
    if(K<asum):
        a_c=i-1
        asum-=A[i]
        break

now=a_c+1
ans=a_c+1
absum=asum
for i in range(M+1):
    while(1):
        if(K<(absum+B[b_c])):
            break
        absum+=B[b_c]
        b_c+=1
        now+=1
    ans=max(ans,now)
    a_c-=1
    absum-=A[a_c+1]
    now=now-1
    if(a_c==-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()))

i = 1
while i < N:
    A[i] = A[i - 1] + A[i]
    i = i + 1

i = 1
while i < M:
    B[i] = B[i - 1] + B[i]
    i = i + 1

sum_list = []

for n in A:
    for m in B:
        sum = n + m
        if sum <= K:
            sum_list.append(sum)

if sum_list:
    X = max(sum_list)
    flag = False
    for n in A:
        for m in B:
            sum = n + m
            if sum is X:
                flag = True
                break
        if flag:
            break
    count = A.index(n) + B.index(m) + 2
    print(count)
else:
    print(0)

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()))
na = []
c = 0
for booka in a:
  c += booka
  na.append(c)
nb = []
d = 0
for bookb in b:
  d += bookb
  nb.append(d)
maxa = 0
for i in range(n-1,-1,-1):
  for j in range(m-1,-1,-1):
    if na[i] + nb[j] <= k:
      maxa = max(maxa,i+j+2)
      break
print(maxa)

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()))
na = []
c = 0
for booka in a:
  c += booka
  na.append(c)
nb = []
d = 0
for bookb in b:
  d += bookb
  nb.append(d)
maxa = 0
for i in range(n):
  for j in range(m):
    if na[i] + nb[j] <= k:
      maxa = max(maxa,i+j+2)
print(maxa)

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import decimal
import itertools
from collections import deque
from functools import reduce
import heapq
#a = int(input())
n, m, k = map(int, sys.stdin.readline().split())
#s = input()
a = list(map(int, sys.stdin.readline().split()))

b = list(map(int, sys.stdin.readline().split()))
a.append(10 ** 10)
b.append(10 ** 10)

ans = 0
time = 0
p = 0
q = 0
for i in range(n+m):
    if a[p] > b[q]:
        if b[q] + time <= k:
            ans += 1
            time += b[q]
            q += 1

        else:
            break

    elif a[p] <= b[q]:
        if a[p] + time <= k:
            ans += 1
            time += a[p]
            p += 1

        else:
            break
        
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import decimal
import itertools
from collections import deque
from functools import reduce
import heapq
#a = int(input())
n, m, k = map(int, sys.stdin.readline().split())
#s = input()
a = list(map(int, sys.stdin.readline().split()))

b = list(map(int, sys.stdin.readline().split()))

c = deque(a)
d = deque(b)

ans = 0
time = 0
x = c.popleft()
y = d.popleft()
for i in range(n+m):
    if x > y:
        if y + time <= k:
            ans += 1
            time += y
            if len(d) > 0:
                y = d.popleft()
            elif len(c) > 0:
                y = 10 ** 10
            else:
                break

        else:
            break

    else:
        if x + time <= k:
            ans += 1
            time += x
            if len(c) > 0:
                x = c.popleft()
            elif len(d) > 0:
                x = 10 ** 10
            else:
                break

        else:
            break

print(ans)

Submission status: Wrong Answer

Solution code:
pile1, pile2, maxt = map(int, input().split())
j=0
p=0
a=0
b=0
books1= list(map(int, input().split()))
books2= list(map(int,input().split()))

books2.sort()


res_list = [] 
i=0
while(i<len(books1) and i<len(books2)): 
	if(a<(maxt-books1[i])):
		a+=books1[i]
		b+=1
		if((a+books2[i])<maxt):
			a+=books2[i]
			b+=1
	i+=1
print(b)

Submission status: Wrong Answer

Solution code:
import bisect

n, m, k = [int(i) for i in input().split()]

a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

if (n > 1):
    for i in range(1,n):
        a[i] += a[i-1]

if (m > 1):
    for i in range(1,m):
        b[i] += b[i-1]

jmax = bisect.bisect(b, k)
jmax = min(m-1, jmax)

count = 0

for i in range(n):
    while(a[i] + b[jmax] > k):
        if (jmax > 0):
            jmax -= 1
        else:
            jmax = -200001
            break
    count = max(count, i + jmax)

    if(jmax == -200001):
        break

if(k < a[0] and k < b[0]):
    print(0)
elif(a[0] <= k and k < b[0]):
    if(n > 1):
        if(k < a[1]):
            print(1)
        else:
            print(count+2)
    else:
        print(1)
elif(b[0] <= k and k < a[0]):
    if(m > 1):
        if(k < m[1]):
            print(1)
        else:
            print(count+2)
    else:
        print(1)
else:
    print(count+2)

Submission status: Wrong Answer

Solution code:
a_count,b_count,time = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

count = 0
for i in range(len(a) + len(b)):
	if len(a) != 0 and len(b) != 0 and time < a[0] and time < b[0]:
		break
	elif len(a) == 0 and time < b[0]:
		break
	elif len(b) == 0 and time < a[0]:
		break
	elif len(a) != 0 and len(b) != 0:
		if a[0] >= b[0]:
			time -= b[0]
			count += 1
			del b[0]
			#print(time)
		else:
			time -= a[0]
			count += 1
			del a[0]
			#print(time)
	elif len(a) == 0 and time >= b[0]:
		time -= b[0]
		count += 1
		del b[0]
		#print(time)
	elif len(b) == 0 and time >= a[0]:
		time -= a[0]
		count += 1
		del a[0]
		#print(time)
print(count)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
import bisect

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = 0
a1 = [0] + list(accumulate(a))
b1 = list(accumulate(b))

for i in range(1, n + 1):
  ren = k - a1[i]
  if ren < 0:
    break
  j = bisect.bisect_right(b1, ren)
  x = max (x, i + j)
print (x)

Submission status: Wrong Answer

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

a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

a.append(200001)
b.append(200001)

ai = 0
bi = 0
sum = 0
count = 0
while(1):
    if(a[ai] <= b[bi]):
        sum += a[ai]
        ai += 1
        count += 1
    else:
        sum += b[bi]
        bi += 1
        count += 1

    if(sum > k):
        count -= 1
        break

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

Submission status: Wrong Answer

Solution code:
a_count,b_count,time = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))

count = 0
for i in range(len(a) + len(b)):
	if len(a) != 0 and len(b) != 0 and time < a[0] and time < b[0]:
		break
	elif len(a) == 0 and time < b[0]:
		break
	elif len(b) == 0 and time < a[0]:
		break
	elif len(a) != 0 and len(b) != 0:
		if a[0] >= b[0]:
			time -= b[0]
			count += 1
			del b[0]
			#print(time)
		else:
			time -= a[0]
			count += 1
			del a[0]
			#print(time)
	elif len(a) == 0 and time >= b[0]:
		time -= b[0]
		count += 1
		del b[0]
		#print(time)
	elif len(b) == 0 and time >= a[0]:
		time -= a[0]
		count += 1
		del a[0]
		#print(time)
print(count)

Submission status: Wrong Answer

Solution code:
n, m, v = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = 0
a1 = [0] * (n + 1)
b1 = [0] * (m + 1)
n1 = n + 1
for i in range(1, n + 1):
  a1[i] = a1[i - 1] + a[i - 1]
  if a1[i] > v:
    n1 = i
    break
m1 = m + 1
for i in range(1, m + 1):
  b1[i] = b1[i - 1] + b[i - 1]
  if b1[i] > v:
    m1 = i
    break
for i in range(n1):
  c = 0
  for j in range(1,m1):
    if a1[i] + b1[j] > v:
      c = i + j - 1
      break
  if x < c:
    x = c
print (x)

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

Submission status: Wrong Answer

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

a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

for i in range(m):
    a.append(b[i])

a.sort()

count = 0
sum = 0
for i in range(n + m):
    sum += a[i]
    if(sum <= k):
        count += 1
    else:
        break

print(count)