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
input = sys.stdin.readline

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

ind1 = 0
ind2 = 0
ans = 0
T = 0
while T <= K:
    if ind1 < N and ind2 < M:
        a1 = A[ind1]; b1 = B[ind2]
        if a1 > b1:
            if T + b1 <= K:
                ans += 1
            T += b1
            ind2 += 1
        else:
            if T + a1 <= K:
                ans += 1
            T += a1
            ind1 += 1
    elif ind1 < N:
        a1 = A[ind1]
        if T + a1 <= K:
            ans += 1
        T += a1
        ind1 += 1
    elif ind2 < M:
        b1 = B[ind2]
        if T + b1 <= K:
            ans += 1
        T += b1
        ind2 += 1
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
from decimal import *
import heapq
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

n, m, k = MAP()
a = LIST()
b = LIST()
ans = 0
a_n = 0
b_n = 0
tim = 0
while tim <= k:
    if a_n == -1 and b_n == -1:
        break
    if a_n == -1:
        pls = b[b_n]
        mode = 1
    elif b_n == -1:
        pls = a[a_n]
        mode = 0
    else:
        pls = min(a[a_n], b[b_n])
        mode = [a[a_n], b[b_n]].index(min(a[a_n], b[b_n]))
    if tim + pls <= k:
        ans += 1
        tim += min(a[a_n], b[b_n])
        if a[a_n] < b[b_n]:
            a_n += 1
        else:
            b_n += 1
        if a_n >= n:
            a_n = -1
        if b_n >= m:
            b_n = -1
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
import bisect
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return x if y == 0 else gcd(y, x%y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

N, M, K = LI()
A = LI()
B = LI()
A.append(INF)
B.append(INF)
now = 0
a = 0
b = 0
ans = 0
while True:
    m = min(A[a], B[b])

    if now + m <= K:
        now += m
        ans += 1

        if m == A[a]:
            a += 1
        else:
            b += 1
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a=0
b=0
t=0
count=0
while a+b<N+M:
    if a==N:
        if t+B[b]<=K:
            t+=B[b]
            count+=1
            b+=1
        else:
            break
    elif b==M:
        if t+A[a]<=K:
            t+=A[a]
            count+=1
            a+=1
        else:
            break
    else:
        if t+min(A[a],B[b])<K:
            if A[a]<B[b]:
                t+=A[a]
                count+=1
                a+=1
            else:
                t+=B[b]
                count+=1
                b+=1
        else:
            break
print(count)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.append(float("INF"))
b.append(float("INF"))
ai = 0
bi = 0
ans = 0
while k > 0:
    if a[ai]<b[bi]:
        k -= a[ai]
        if k<0: break
        ai += 1
        ans += 1
    else:
        k -= b[bi]
        if k<0: break
        bi += 1
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    inf=10**10
    n,m,k=MI()
    aa=LI()+[inf]
    bb=LI()+[inf]
    ans=0
    i=j=0
    while 1:
        if aa[i]<bb[j]:
            cur=aa[i]
            i+=1
        else:
            cur=bb[j]
            j+=1
        if cur>k:break
        k-=cur
        ans+=1
    print(ans)

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()))
a.append(float("INF"))
b.append(float("INF"))

ans = 0
na = nb = 0
while k > 0:
    x = a[na]
    y = b[nb]
    if x <= y:
        if k >= x:
            ans += 1
            na += 1
            k -= x
        else:
            print(ans)
            exit()
    else:
        if k >= y:
            ans += 1
            nb += 1
            k -= y
        else:
            print(ans)
            exit()
    
print(ans)

Submission status: Wrong Answer

Solution code:
INF = 10**12

N, M, K = map(int, input().split())
As = list(map(int, input().split())) + [INF]
Bs = list(map(int, input().split())) + [INF]

iA = iB = 0
ans = 0
acc = 0
for _ in range(N+M):
    if As[iA] < Bs[iB]:
        acc += As[iA]
        if acc > K:
            break
        iA += 1
    else:
        acc += Bs[iB]
        if acc > K:
            break
        iB += 1
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
arr1 = [int(j) for j in input().split()]
arr2 = [int(j) for j in input().split()]

ind1, ind2 = 0, 0
cur,ans = 0, 0
while ind1 != n and ind2 != m:

	if cur+arr1[ind1] > k and cur+arr2[ind2] > k:
		break

	if arr1[ind1] <= arr2[ind2]:
		cur += arr1[ind1]
		ind1 += 1
		ans += 1
	else:
		cur += arr2[ind2]
		ind2 += 1
		ans += 1

while ind1 != n:
	if cur + arr1[ind1] > k:
		break

	cur += arr1[ind1]
	ind1 += 1
	ans += 1

while ind2 != m:
	if cur + arr2[ind2] > k:
		break

	cur += arr2[ind2]
	ind2 += 1
	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()))
ans = 0
h = 0
i = 0
j = 0
while h < K:
    if ans == N+M:
        break
    if i == N:
        h += b[j]
        j += 1
        if h <= K:
            ans += 1
    elif j == M:
        h += a[i]
        i += 1
        if h <= K:
            ans += 1
    else:
        if a[i] <= b[j]:
            h += a[i]
            i += 1
            if h <= K:
                ans += 1
        else:
            h += b[j]
            j += 1
            if h <= K:
                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()))
AX = [0];BX = [0]

for a in A:
    AX.append(AX[-1]+a)
for b in B:
    BX.append(BX[-1]+b)    

ans = 0
j = M
for i in range(1,N+1):
    if AX[i] > K:
        break
    while AX[i]+BX[j] > K:
        j -= 1
    ans = max(ans,i+j)
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,m,k=nii()
a=lnii()
b=lnii()

a_inx=0
b_inx=0
t=0
ans=0

while t<=k:
  if a_inx<=len(a)-1:
    a_c=a[a_inx]
  else:
    a_c=10**10
  if b_inx<=len(b)-1:
    b_c=b[b_inx]
  else:
    b_c=10**9

  if a_c<=b_c:
    ans+=1
    t+=a_c
    a_inx+=1
  else:
    ans+=1
    t+=b_c
    b_inx+=1

print(ans-1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
#from heapq import heappop, heappush
#from collections import OrderedDict, defaultdict
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque
#import numba

def run():
    N, M, K = map(int, sysread().split())
    A = list(map(int, sysread().split()))
    B = list(map(int, sysread().split()))

    AB = sorted(A + B)

    ret = 0
    time = 0
    for k in AB:
        time += k
        if time > K:
            print(ret)
            return None
        else:
            ret += 1
    print(ret)

if __name__ == "__main__":
    run()

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

    t = 0
    i, j = 0, 0
    ans = 0
    while t < K:
        a, b = float('inf'), float('inf')
        if i < len(A):
            a = A[i]
        if j < len(B):
            b = B[i]
        if a < b:
            if t + a  <= K:
                i += 1
                ans += 1
                t += a
            else:
                break
        elif b <= a:
            if t + b <= K:
                j += 1
                ans += 1
                t += b
            else:
                break
    return ans

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

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
b=[0]+list(map(int,input().split()))
for i in range(n):
	a[i+1]+=a[i]
for i in range(m):
	b[i+1]+=b[i]
print(a,b)
from bisect import bisect_right
ans=0
for i in range(n+1):
	if k-a[i]>0:
		r=bisect_right(b,k-a[i])
		ans=max(r+i-1,ans)
	else:
		break
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int,input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
cnt = 0
for i in a:
	if i<=k:
		k-=i 
		cnt+=1
for i in b:
	if i<=k:
		k-=i 
		cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    N, M, K = MI()
    A = LI()
    B = LI()
    heapify(A)
    heapify(B)

    ans = 0
    sm = 0
    for _ in range(N+M):
        if A and B:
            a = heappop(A)
            b = heappop(B)
            if a < b:
                if a + sm <= K:
                    sm = sm + a
                    ans += 1
                    heappush(B, b)
                else:
                    break
            else:
                if b + sm <= K:
                    sm = sm + b
                    ans += 1
                    heappush(A, a)
                else:
                    break
        elif A:
            a = heappop(A)
            if sm + a <= K:
                sm = sm + a
                ans += 1
            else:
                break
        elif B:
            b = heappop(B)
            if sm + b <= K:
                sm = sm + b
                ans += 1
        else:
            break
    print(ans)





if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from itertools import accumulate
from bisect import bisect_right
sys.setrecursionlimit(10**8)
INF = float("inf")


def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    ab = sorted(A+B)
    ab = list(accumulate(ab))
    i = bisect_right(ab, K)
    print(i)

    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

def solve():
      input = sys.stdin.readline
      N, M, K = map(int, input().split())
      A = [int(a) for a in input().split()]
      B = [int(b) for b in input().split()]
      ad, bd = deque(), deque()
      for a in A: ad.append(a)
      for b in B: bd.append(b)

      count = 0
      for i in range(N + M):
            ah, bh = 10 ** 10, 10 ** 10
            if ad: ah = ad.popleft()
            if bd: bh = bd.popleft()

            if ah > K and bh > K: break
            count += 1
            if ah <= bh:
                  K -= ah
                  bd.appendleft(bh)
            else:
                  K -= bh
                  ad.appendleft(ah)
      print(count)

      return 0

if __name__ == "__main__":
      solve()

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=sorted(A+B)
total,count=0,0
for i in range(len(time)):
    total+=time[i]
    if total>K:
        break
    count+=1
print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from itertools import accumulate

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(accumulate(sorted(a + b)))
for i in range(n + m):
    if c[i] > k:
        print(i)
        exit()
print(n + m)

Submission status: Wrong Answer

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

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

C = A+B
C.sort()

ans = 0
count = 0
for c in C:
  ans += c
  if ans <= K:
    count += 1
  else:
    break

print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque
N, M, K = map(int, input().split())
A = deque(list(map(int, input().split())))
B = deque(list(map(int, input().split())))
ans = 0
t = 0
while t < K:
    if A and B:
        if A[0] < B[0]:
            x = A.popleft()
        else:
            x = B.popleft()
    elif A:
        x = A.popleft()
    elif B:
        x = B.popleft()
    else:
        break
    if t + x <= K:
        t += x
        ans += 1
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""

a,b,t = m()

aa = cl.deque(l())

bb = cl.deque(l())

co = 0

ccc = 0
while True:

	if len(aa) != 0 and len(bb) != 0:
		aaa = aa.popleft()
		bbb = bb.popleft()

		if aaa <= bbb:
			if co + aaa <= t:
				co += aaa
				ccc += 1
				bb.appendleft(bbb)
			else:
				break
		else:
			if co + bbb <= t:
				co += bbb
				ccc += 1
				bb.appendleft(aaa)
			else:
				break

	elif len(aa) != 0:
		aaa = aa.popleft()
		if co + aaa <= t:
			co += aaa
			ccc += 1
			bb.appendleft(bbb)
		else:
			break
	elif len(bb) != 0:
		bbb = bb.popleft()
		if co + bbb <= t:
			co += bbb
			ccc += 1
			bb.appendleft(aaa)
		else:
			break
	else:
		break
print(ccc)

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=sorted(a+b)
cnt=0
ans=0
flag=True
for i in c:
  cnt+=i
  if cnt>k:
    flag=False
    print(ans)
    break
  else:
    ans+=1
if flag:
  print(n+m)

Submission status: Wrong Answer

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

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A = list(accumulate(A))
B = list(accumulate(B))
ans = 0
for i in range(N):
    if A[i] > K:
        break
    j = bisect_right(B, K - A[i])
    ans = max(ans, i + j + 1)
print(ans)

Submission status: Wrong Answer

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

A_acc=[0]
B_acc=[0]

for a in A:
    A_acc.append(a+A_acc[-1])
for b in B:
    B_acc.append(b+B_acc[-1])

ans=0
for i in range(len(A_acc)):
    a_time = A_acc[i]
    remain = K-a_time
    if remain>0:
        idx = bisect.bisect_right(B_acc,remain)
        ans=max(ans,i+idx-1)
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()]

minites = k
c = 0
while k > 0 and (len(a) or len(b)):
    if len(a) > 0 and len(b) > 0:
        if a[-1] < b[-1]:
            k -= a[-1]
            a.pop()
        else:
            k -= b[-1]
            b.pop()
    elif len(a) > 0:
        k -= a[-1]
        a.pop()
    else:
        k -= b[-1]
        b.pop()
    if k >= 0:
        c += 1
print(c)

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M, K, *AB = map(int, read().split())
    A = AB[:N]
    B = AB[N:]
    
    A = A[::-1]
    B = B[::-1]
    
    ans = 0
    time = 0
    while time < K:
        if not A and not B:
            break
        if not A:
            time += B.pop()
        elif not B:
            time += A.pop()
        else:
            if A[-1] < B[-1]:
                time += A.pop()
            else:
                time += B.pop()
        
        if time > K:
            break
        ans += 1
    
    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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()))
INF = 1001001001001001
a.append(INF)
b.append(INF)
ans = 0

while (len(a)>1 or len(b)>1) and k>0:
    if a[0] <= b[0]:
        ans += 1
        k -= a[0]
        a.popleft()
    else:
        ans += 1
        k -= b[0]
        b.popleft()
if k<0:
    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()))

ai = 0
bi = 0
cnt = 0
while True:
    if ai >= n and bi >= m:
        break
    if ai == n:
        if k - b[bi] < 0:
            break
        k -= b[bi]
        cnt += 1
        bi += 1
        continue
    if bi == m:
        if k - a[ai] < 0:
            break
        k -= a[ai]
        cnt += 1
        ai += 1
        continue
    if a[ai] < b[bi] :
        if k - a[ai] < 0:
            break
        k -= a[ai]
        cnt += 1
        ai += 1
        continue
    elif a[bi] <= b[bi]:
        if k - b[bi] < 0:
            break
        k -= b[bi]
        cnt += 1
        bi += 1
        continue
    break
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()))

C = A+B
C.sort()
print(C)

ans = 0
count = 0
for c in C:
  ans += c
  if ans <= K:
    count += 1
  else:
    break

print(count)

Submission status: Wrong Answer

Solution code:
"""
~~ Author : Bhaskar
~~ Dated : 10~06~2020
"""

import sys
from bisect import *
from math import floor,sqrt,ceil,factorial as F,gcd,pi
from itertools import chain,combinations,permutations,accumulate
from collections import Counter,defaultdict,OrderedDict,deque
from array import array
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
mod = 1000000007
ch = "abcdefghijklmnopqrstuvwxyz"
lcm = lambda a,b : (a*b)//gcd(a,b)
setbit = lambda x : bin(x)[2:].count("1")
input = lambda : sys.stdin.readline()

def solve():
    n, m, k = map(int, sys.stdin.readline().split())
    a = list(map(int, sys.stdin.readline().split()))
    b = list(map(int, sys.stdin.readline().split()))
    a = a + b
    a.sort()
    ans = 0
    s = 0
    for i in range(len(a)):
        s += a[i]
        if s <= k:
            ans += 1
    print(ans)
    


if __name__ == "__main__":
    try:
        sys.stdin = open('input.txt','r')
        sys.stdout = open('output.txt','w')
    except:
       pass
    solve()

Submission status: Wrong Answer

Solution code:
from collections import deque
INF = 10**10
N,M,K = map(int,input().split())
A = list(map(int,input().split()))+[INF]
B = list(map(int,input().split()))+[INF]
A = deque(A)
B = deque(B)
ans = 0
tmp = 0
a = A.popleft()
b = B.popleft()
while True:
    if a<b:
        if tmp+a>K:
            break
        tmp += a
        ans += 1
        a = A.popleft()
    else:
        if tmp+b>K:
            break
        tmp += b
        ans += 1
        b = B.popleft()
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()))

from itertools import accumulate
import bisect
z = list(accumulate(sorted(a+b)))

print(bisect.bisect_right(z, k))

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: map(int, readline().split()) # input multiple int 
nl = lambda: list(map(int, readline().split())) # input multiple int to list

n, m, k = nm()
A = nl()
B = nl()
books = sorted(A + B)
cnt = 0
time = 0
for b in books:
    if b + time <= k:
        time += b
        cnt += 1
    else:
        break
print(cnt)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
A = list(map(int, input().split()))[::-1]
B = list(map(int, input().split()))[::-1]
ans = 0
while (A or B) and k > 0:
    if A and B:
        a, b = A[-1], B[-1]
        if a < b:
            if a > k:
                break
            k -= A.pop()
            ans += 1
        else:
            if b > k:
                break
            k -= B.pop()
            ans += 1
    else:
        if A:
            a = A.pop()
            if a > k:
                break
            k -= a
            ans += 1
        else:
            b = B.pop()
            if b > k:
                break
            k -= b
            ans += 1
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()]
i = j = 0
book = 0
while i < len(A) or j < len(B):
    if i < len(A) and j < len(B):
        b = min(A[i], B[j])
        if A[i] > B[j]:
            j += 1
        else:
            i += 1
    elif i < len(A):
        b = A[i]
        i += 1
    elif j < len(B):
        b = B[j]
        j += 1
    if K - b > 0:
        book += 1
        K -= b
    elif K - b == 0:
        book += 1
        break
    else:
        break
print(book)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    N, M, K = [int(x) for x in input().strip().split()]
    AB = sorted([int(x) for x in input().strip().split()] + [int(x) for x in input().strip().split()])
    cumsum = 0
    ans = 0
    for ab in AB:
        if cumsum + ab <= K:
            cumsum += ab
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A = list(accumulate(A))
B = list(accumulate(B))
ans = 0
for i in range(N):
    j = bisect_right(B, K - A[i])
    if j > 0:
        ans = max(ans, i + j + 1)
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))


def main():
    n,m,k = na()
    hon = na()
    hon += na()
    hon.sort()
    ans = 0
    for i in range(n+m):
        if k > 0:
            k -= hon[i]
            if k >= 0:
                ans += 1
        else:
            break
    print(ans)
    return


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()))
A.reverse()
B.reverse()

t = 0
cnt = 0
while A and B and t <= K:
    if A[-1] < B[-1]:
        t += A.pop()
    else:
        t += B.pop()
    cnt += 1

if not A:
    A = B

while A and t <= K:
    t += A.pop()
    cnt += 1

print(cnt - (t > 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 = [0] + list(reversed(b)) + a
for i in range(n + m):
    c[i + 1] += c[i]
r = m
ans = 0
for l in range(n + m):
    while r <= n + m and c[r] - c[l] <= k:
        ans = max(ans, r - l)
        r += 1
print(ans)

Submission status: Wrong Answer

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

A = A[::-1]
B = B[::-1]

ret = 0
t = 0
while True :
  a = float('inf')
  b = float('inf')
  if A :
    a = A[-1]
  if B :
    b = B[-1]
    
  if (a + t > K) and (b + t > K) :
    break
    
  if a <= b :
    t += a
    ret += 1
    A.pop()
  else :
    t += b
    ret += 1
    B.pop()
    
print(ret)

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()))
nowa = 0
nowb = 0
ans = 0
while k > 0:
	if nowa < n and nowb < m:
		if a[nowa] < b[nowb]:
			k -= a[nowa]
			nowa += 1
			ans += 1
		else:
			k -= b[nowb]
			nowb += 1
			ans += 1
	elif nowa < n:
		k -= a[nowa]
		nowa += 1
		ans += 1
	elif nowb < m:
		k -= b[nowb]
		nowb += 1
		ans += 1
	else:
		break
	if k < 0:
		ans -= 1
		break
print(ans)

Submission status: Wrong Answer

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

ans = 0
time = 0
ac = 0;bc = 0

for i in range(n+m):
	if time == k:break
	if time > k:
		ans -= 1
		break
	if ac < n and bc < m:
		if a[ac] > b[bc]:
			ans += 1
			time += b[bc]
			bc += 1
		else:
			ans += 1
			time += a[ac]
			ac += 1
	elif ac >= n and bc < m:
		ans += 1
		time += b[bc]
		bc += 1
	elif ac < n and bc >= m:
		ans += 1
		time += a[ac]
		ac += 1
	else:
		break

print(ans)