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 bisect
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

# cumsum
a_sum = [0] * n
a_sum[0] = a[0]
for i in range(1, n):
    a_sum[i] = a_sum[i-1] + a[i]

b_sum = [0] * m
b_sum[0] = b[0]
for i in range(1, m):
    b_sum[i] = b_sum[i-1] + b[i]

ans = 0
for i in range(n):
    a_total = a_sum[i]
    if a_total > k: break
    j = bisect.bisect_right(b_sum, k - a_total)
    ans = max(ans, i + j + 1)
print(ans)

Submission status: Wrong Answer

Solution code:
import math


n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
acount=0
bcount=0
c=0

while True:
    if k<0:
        break
    if k==0:
        c+=1
        break
    if acount>=n and bcount>=m:

        break

    if acount<n and bcount<m:
        if a[acount]<b[bcount]:

            k=k-a[acount]
            acount+=1
            c+=1
            continue

        if a[acount]>=b[bcount]:
            k=k-b[bcount]
            bcount+=1
            c+=1
            continue

    if acount>=n:
        k = k - b[bcount]
        bcount += 1
        c += 1
        continue
    if bcount>=n:
        k = k - a[acount]
        acount += 1
        c += 1
        continue
print(c-1)

Submission status: Wrong Answer

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

l = a + b
l_sort = sorted(l)

ans = 0
kingaku = 0
for i in range(n+m):
  if kingaku > k:
    print(ans - 1)
    break
  else:
    kingaku += l_sort[i]
    ans += 1
    continue

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque,Counter
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n,m,k = IL()
    a = deque(IL())
    b = deque(IL())
    val = 0
    ans = 0
    while val<k:
        if not a or not b:  break
        if k<val+a[0] and k<val+b[0]:   break
        if a[0]<b[0]:
            val += a.popleft()
        else:
            val += b.popleft()
        ans += 1
    
    if val<k:
        if a:
            while val+a[0]<=k and a:
                val += a.popleft()
                ans += 1
                if not a:   break
        elif b:
            while val+b[0]<=k and b:
                val += b.popleft()
                ans += 1
                if not b:   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())) # list()でリスト化、それを変数に代入。
b = list(map(int, input().split())) # list()でリスト化、それを変数に代入。
ans = 0
c_a = 0
c_b = 0
time = 0
a.append(10**9 + 1)
b.append(10**9 + 1)
while True:
    if time + min(a[c_a],b[c_b])>k:
        break
    if a[c_a]>b[c_b]:
        time += b[c_b]
        c_b += 1
    else:
        time += a[c_a]
        c_a += 1
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
#!python3.8
# -*- coding: utf-8 -*-
# abc172/abc172_c
import sys
from collections import deque

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, M, K = i2nn()
    A = deque(i2nn())
    B = deque(i2nn())
    t = 0
    n = 0
    while True:
        if A and B:
            u = A.popleft() if A and (A[0] < B[0]) else B.popleft()
            if t + u > K:
                break
            t += u
            n += 1
        elif A:
            u = A.popleft()
            if t + u > K:
                break
            t += u
            n += 1
        elif B:
            u = B.popleft()
            if t + u > K:
                break
            t += u
            n += 1
        else:
            break
        
    print(n)
    return

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

suma=[]
tmp=0
for aa in a:
    tmp+=aa
    suma.append(tmp)

sumb=[]
tmp=0
for bb in b:
    tmp+=bb
    sumb.append(tmp)

ans=0

for i in range(n):
    if suma[i]<=k:
        for j in range(m):
            if suma[i]+sumb[j]<=k:
                ans=max(ans,i+j+2)
            else:
                break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("out.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

# @lru_cache(None)
t=1
# t=int(input())
for _ in range(t):
    n,m,k=l()
    A=l()
    B=l()
    i=0
    j=0
    B=A[::-1]+B
    pref=[0 for i in range(n+m+1)]
    for i in range(n+m):
        pref[i+1]=pref[i]+B[i]
    ans=0
    for i in range(n+1):
        x=br(pref,pref[i]+k)
        if x<n-1:
            continue
        ans=max(ans,x-i-1)
    print(ans)

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]

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

if k <= 0:
    print(ans - 1)
    exit()
print(ans)

Submission status: Wrong Answer

Solution code:
n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = n
B = 0
if (a[0]>k):
    A = 0
for i in range(1,n):
    a[i] += a[i-1]
    if (a[i]>k):
        A = i
for i in range(1,m):
    b[i] += b[i-1]
if (a[0]>k):
    A = 0
ans = A
while True:
    if (A<0):
        break
    if (B>=m):
        break
    B += 1
    if (A==0):
        for i in range(m):
            if (b[i]>k):
                print(i)
                exit()
            print(len(b))
            exit()
    if (a[A-1]+b[B-1] >k):
        B -= 1
        A -= 1
    else:
        ans = max(ans,A+B)
print(ans)

Submission status: Wrong Answer

Solution code:
"""
    こんにちは。これはクシャルです
    
    Author : thekushalghosh (クシャル)
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time
start_time = time.time()
##########################################################################
################# ---- THE ACTUAL CODE STARTS BELOW ---- #################

def solve():
    n,m,k = invr()
    a = list(reversed(inlt()))
    b = list(reversed(inlt()))
    c = 0
    while True:
        if a and b:
            if a[-1] < b[-1] and k - a[-1] >= 0:
                k = k - a.pop()
                c = c + 1
            elif a[-1] >= b[-1] and k - b[-1] >= 0:
                k = k - b.pop()
                c = c + 1
            else:
                break
        elif a and k - a[-1] >= 0:
            k = k - a.pop()
            c = c + 1
        elif b and k - b[-1] >= 0:
            k = k - b.pop()
            c = c + 1
        else:
            break
    print(c)
            
################## ---- THE ACTUAL CODE ENDS ABOVE ---- ##################
##########################################################################
 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
        sys.stdout.close()
    
#---------------------- USER DEFINED INPUT FUNCTIONS ----------------------#
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))
 
#------------------ USER DEFINED PROGRAMMING FUNCTIONS ------------------#
def counter(a):
    q = [0] * max(a)
    for i in range(len(a)):
        q[a[i] - 1] = q[a[i] - 1],1
    return(q)
 
def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97],1
    return(q)

def factors(n):
    q = []
    for i in range(1,int(n ** 0.5) + 1):
        if n % i == 0: q.append(i); q.append(n // i)
    return(list(sorted(list(set(q)))))

def prime_factors(n):
    q = []
    while n % 2 == 0: q.append(2); n = n // 2
    for i in range(3,int(n ** 0.5) + 1,2):
        while n % i == 0: q.append(i); n = n // i
    if n > 2: q.append(n)
    return(list(sorted(q)))

#-----------------------------------------------------------------------#
        
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
main()

Submission status: Wrong Answer

Solution code:
from collections import deque

n, m, k = [int(e) for e in input().split()]
a = deque([int(e) for e in input().split()])
b = deque([int(e) for e in input().split()])

count = 0
while True:
    if len(a) > 0 and a[0] <= k:
        k -= a.popleft()
        count += 1
        continue
    if len(b) > 0 and b[0] <= k:
        k -= b.popleft()
        count += 1
        continue
    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.reverse()
B.reverse()

i,j=len(A)-1,len(B)-1
count=0
OVER = pow(10,9)+1
while True:
    a = OVER if i < 0 else A[i]
    b = OVER if j < 0 else B[j]
    if a <= b:
        k-=a
        i-=1
    else:
        k-=b
        j-=1
    if k < 0:
        break
    else:
        count+=1
print(count)

Submission status: Wrong Answer

Solution code:
an,bm,khun = map(int,input().split())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))
alist.append(10**9+1)
blist.append(10**9+1)
count = 0
for i in range(an+bm):
    if alist[0]<=blist[0] and khun >=alist[0]:
        khun -= alist[0]
        count += 1
        alist.pop(0)
    elif khun >= blist[0]:
        khun -= blist[0]
        count += 1
        blist.pop(0)
    else:
        break;
print(count)

Submission status: Wrong Answer

Solution code:
import bisect

N, M, K = map(int, input().split())
Alist = [0] + list(map(int, input().split()))
Blist = list(map(int, input().split()))

B = [Blist[0]]
for b in Blist[1:]:
    B.append(b + B[-1])

print(B)

sums = 0
ans = 0
for idx, a in enumerate(Alist):
    sums += a
    if sums > K:
        break
    k = K - sums
    tmp = bisect.bisect_right(B, k)
    ans = max(ans, idx + tmp)

print(ans)

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())))
cnt = 0
ans = 0
for i in range(n + m):
    if a == deque([]):
        if cnt + b[0] > k:break
    elif b == deque([]):
        if cnt + a[0] > k:break
    elif cnt + min(a[0], b[0]) > k:
        break
    if a == deque([]):
        cnt += b[0]
        b.popleft()
    elif b == deque([]):
        cnt += a[0]
        a.popleft()
    elif a[0] >= b[0]:
        cnt += b[0]
        b.popleft()
    else:
        cnt += a[0]
        a.popleft()
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:

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

time = 0
count = 0

while time <= K:
    if len(A) <= 0 and len(B) <= 0:
        break
    a = 1000000001
    b = 1000000001
    if len(A) > 0:
        a = A.pop()
    if len(B) > 0:
        b = B.pop()

    if a < b:
        B.append(b)
        time += a
    else:
        A.append(a)
        time += b
    count += 1

print(count - 1)

Submission status: Wrong Answer

Solution code:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
amount=0
count=0
i=0
j=0         
while amount<k:
    if i<n and j<m:
        if a[i]<b[j]:
            if a[i]+amount <= k:       
                count+=1
                amount+=a[i]
                i+=1
            else:
                break
        else:
            if b[j]+amount <= k:       
                count+=1
                amount+=b[j]
                j+=1
            else:
                break
    elif i<n and j>=m:
        if a[i]+amount <= k:       
                count+=1
                amount+=a[i]
                i+=1
        else:
            break
    elif i>=n  and j<m:
        if b[j]+amount <= k:       
                count+=1
                amount+=b[j]
                j+=1
        else:
            break
    if i>=n and j>=m:
        break
print(count)

Submission status: Wrong Answer

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

count = 0
sum = 0
while True:
    if len(A) == 0 and len(B) == 0:
        break
    elif len(A) == 0:
        if sum + B[0] <= K:
            sum += B[0]
            del B[0]
            count += 1
            #print("B:{}".format(B))
        else:
            break
    elif len(B) == 0:
        if sum + A[0] <= K:
            sum += A[0]
            del A[0]
            count += 1
            #print("A:{}".format(A))
        else:
            break
    elif A[0] <= B[0]:
        if sum + A[0] <= K:
            sum += A[0]
            del A[0]
            count += 1
            #print("A:{}".format(A))
        else:
            break

    elif A[0] > B[0]:
        if sum + B[0] <= K:
            sum += B[0]
            del B[0]
            count += 1
            #print("B:{}".format(B))
        else:
            break
print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
# stdin = open("sample.txt")

MOD = 1000000007
INF = float('inf')
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

def keta(kazu): # 入力されたintを桁ごとに分解，リストで出力
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers): # 最小公倍数
    return reduce(math.gcd, numbers)

def combination(m,n): # mCn
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def pow_k(x,n):  # (x**n)の計算の高速化
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x

def main():
    n,m,k= [int(x) for x in stdin.readline().rstrip().split()]
    a = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
    b = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
    a_now = 0
    b_now = 0
    ans = 0
    
    while k > 0:
        if a_now >= n:
            a_check = INF
        else:
            a_check = a[a_now]
        if b_now >= m:
            b_check = INF
        else:
            b_check = b[b_now]
        if a_now == INF and b_now == INF:
            break
        
        if a_check <= b_check:
            k -= a_check
            a_now += 1
            # print("a")
        elif a_check > b_check:
            k -= b_check
            b_now += 1
            # print("b")
        if k >= 0:
            ans += 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()))
if sum(A)+sum(B) <= K:
  print(N+M)
else:
  a1 = 0
  b1 = 0
  S = 0
  k = 0
  while S <= K:
    if a1 <N and b1<M:
      if A[a1] < B[b1]:
        S += A[a1]
        k += 1
        a1 += 1
      else:
        S += B[b1]
        k += 1
        b1 += 1
    elif a1 == N:
      S += B[b1]
      k += 1
      b1 += 1
    else:
      S += A[a1]
      k+= 1
      a1 += 1
  if S > K:
    print(k-1)
  else:
    print(k)

Submission status: Wrong Answer

Solution code:
import bisect


n, m, k = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
A.insert(0, 0)
B.insert(0, 0)

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

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


res = 0
for i in range(len(A)):
    if k < A[i]:
        break

    j = bisect.bisect_left(B, k - A[i])
    if j < len(B) and B[j] > k - A[i]:
        j -= 1


    cnt = i + j
    res = max(res, cnt)
print(res)

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


n, m, k = inpl()
a = inpl()
b = inpl()
tmp = 0
for i in range(len(a)):
    tmp += a[i]
    a[i] = tmp
tmp = 0
for i in range(len(b)):
    tmp += b[i]
    b[i] = tmp
ans = 0
a_start = bisect.bisect_right(a, k)
for a_amount in range(a_start, -1, -1):
    new_k = k - a[a_amount - 1]
    b_amount = bisect.bisect_right(b, new_k)
    ans = max(ans, a_amount + b_amount)
    print(a_amount, b_amount)
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
cnt = 0
time = 0
flag = 0
for i in range(m + n):
    if a == n:
        if b == m:
            break
        time += B[b]
        b += 1
        cnt += 1
        if time > k:
            cnt -= 1
            lag = 1
            break
        continue
    elif b == m:
        time += A[a]
        a += 1
        cnt += 1
        if time > k:
            cnt -= 1
            flag = 1
            break
        continue
    if A[a] < B[b]:
        time += A[a]
        a += 1
        cnt += 1
    else:
        time += B[b]
        b += 1
        cnt += 1
    if time > k:
        cnt -= 1
        flag = 1
        break
if not flag:
    if time > k:
        cnt -= 1


print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect_right

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

ap = [0 for i in range(n)]
bp = [0 for j in range(m)]

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

for i in range(m):
	if i == 0:
		bp[i] = b[i]
	else: 
		bp[i] = b[i] + bp[i - 1]

bestRes = 0

#print(bp)

def search(x):
	left = 0 
	right = m - 1
	while right - left > 1:
		mid = left + (right - left) // 2
		if bp[mid] == x:
			return mid

		if bp[mid] < x:
			right = mid - 1
		else:
			left = mid + 1


	if bp[right] <= x:
		return right
	elif bp[left] <= x:
		return left
	else:
		return left - 1

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

	rest = k - ap[i]

	if bp[0] > rest:
		bestRes = max(bestRes, i)

	else:
		count = bisect_right(bp, rest) + 1
		#print(i, rest, count)
		bestRes = max(bestRes, i + count)


if k > bp[0]:
	bestRes = max(bestRes, bisect_right(bp, k) + 1)

print(bestRes)

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()
#print(A,B)

t = 0
ans = 0
while True:
    #print(t)
    if t >= K or (A and t + A[-1] > K and B and t + B[-1] > K):
        break
    
    if A and B:
        if A[-1] <= B[-1]:
            if t + A[-1] <= K:
                t += A.pop()
                ans += 1
        else:
            if t + B[-1] <= K:
                t += B.pop()
                ans += 1
    elif A:
        if t + A[-1] <= K:
            t += A.pop()
            ans += 1
    elif B:
        if t + B[-1] <= K:
            t += B.pop()
            ans += 1
    else:
        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()))

jikan=0
count=0
while True:
    if len(A)==0 and len(B)==0:
        count+=1
        break

    elif len(A)==0:
        jikan+=B[0]
        count+=1
        del B[0]
        if jikan>K:
            break

    elif len(B)==0:
        jikan+=A[0]
        count+=1
        del A[0]
        if jikan>K:
            break
    else:
        if A[0] <= B[0]:
            jikan+=A[0]
            count+=1
            del A[0]
        if jikan>K:
            break
        else:
            jikan+=B[0]
            count+=1
            del B[0]
            if jikan>K:
                break
    #print('A,B:', A,B)

print(count-1)

Submission status: Wrong Answer

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

timecnt = 0
cnt = 0
while True:
    minone = 0
    if len(a) != 0 and len(b) != 0:
        if a[0] <= b[0]:
            minone = a[0]
            a.pop(0)
        else:
            minone = b[0]
            b.pop(0)
    elif len(a) == 0 and len(b) != 0:
        minone = b[0]
        b.pop(0)
    elif len(a) != 0 and len(b) == 0:
        minone = a[0]
        a.pop(0)
    elif len(a) == 0 and len(b) == 0:
        break
    timecnt += minone
    if timecnt <= k:
        cnt += 1
    else:
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
def whichDesk(a, b):
    if len(a) == 0:
        return 2
    elif len(b) == 0:
        return 1
    elif a[0] > b[0]:
        return 2
    elif a[0] < b[0]:
        return 1
    else:
        return whichDesk(a[1:], b[1:])

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

t = 0
cnt = 0

while t <= k and (len(a) > 0 or len(b) > 0):
    if whichDesk(a, b) == 2:
        t += b[0]
        b.pop(0)
    else:
        t += a[0]
        a.pop(0)
    if t <= k:
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

    ad = deque()
    ad.extend(A)
    bd = deque()
    bd.extend(B)

    ans = 0
    k = 0
    while True:
        if len(ad) == 0 and len(bd) == 0:
            break
        elif len(ad) == 0:
            x = bd.popleft()
        elif len(bd) == 0:
            x = ad.popleft()
        else:
            if ad[0] < bd[0]:
                x = ad.popleft()
            else:
                x = bd.popleft()
        
        if k + x <= K:
            k += x
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque
def readinput():
    n,m,k=list(map(int,input().split()))
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    return n,m,k,a,b

def main(n,m,k,a,b):
    qa=deque(a)
    qb=deque(b)
    count=0
    res=k
    while(len(qa)>0 and len(qb)>0):
        if qa[0] < qb[0]:
            res-=qa[0]
            qa.popleft()
        else:
            res-=qb[0]
            qb.popleft()
        if res<0:
            return count
        count+=1
    else:
        if len(qa)==0:
            while(len(qb)>0):
                res-=qb[0]
                qb.popleft()
                if res<0:
                    return count
                count+=1
            return count
        else:
            while(len(qa)>0):
                res-=qa[0]
                qa.popleft()
                if res<0:
                    return count
                count+=1
            return count

if __name__=='__main__':
    n,m,k,a,b=readinput()
    ans=main(n,m,k,a,b)
    print(ans)

Submission status: Wrong Answer

Solution code:


import sys
import math
import itertools
import collections

def solve(N,M,K,A,B):
    total = 0
    counter = 0
    while True:
        if len(B) == 0:
            for a in A:
                if K - total >= a:
                    total += a
                    counter += 1
                else:
                    break
            break
        elif len(A) == 0:
            for b in B:
                if K - total >= b:
                    total += b
                    counter += 1
                else:
                    break
            break
        elif (K - total) >= min(A[0],B[0]):
            if A[0] < B[0]:
                total += A.pop(0)
            else:
                total += B.pop(0)
            counter += 1
        elif (K - total) >= max(A[0],B[0]):
            if A[0] > B[0]:
                total += A.pop(0)
            else:
                total += B.pop(0)
            counter += 1
        else:
            break
    return counter
def main():
    N,M,K = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    # solve()
    print(solve(N,M,K,A,B))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
nums=input().split()
a=int(nums[0])
b=int(nums[1])
n=int(nums[2])
lista=input().split()
listb=input().split()

count=0
time=0
while len(lista)!=0 and len(listb)!=0:
  ta=int(lista[0])
  tb=int(listb[0])
  if ta < tb:
    if ta+time>n:
      print(count)
      sys.exit()
    else:
      time+=ta
      count+=1
      lista.pop(0)
  else:
    if tb+time>n:
      print(count)
      sys.exit()
    else:
      time+=tb
      count+=1
      listb.pop(0)

while len(lista)!=0:
  ta=int(lista[0])
  if ta+time>n:
    print(count)
    sys.exit()
  else:
    time+=ta
    count+=1
    lista.pop(0)

while len(listb)!=0:
  tb=int(listb[0])
  if tb+time>n:
    print(count)
    sys.exit()
  else:
    time+=tb
    count+=1
    listb.pop(0)

print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

A = deque(A)
B = deque(B)

ans = 0
left_time = K
while True:
    if len(A) != 0 and len(B) == 0:
        val = A.popleft()
    elif len(A) == 0 and len(B) != 0:
        val = B.popleft()
    elif len(A) == 0 and len(B) == 0:
        break
    elif A[0] <= B[0]:
        val = A.popleft()
    else:
        val = B.popleft()

    left_time -= val
    if left_time < 0:
        break
    else:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
(a,b,c)=[int(x) for x in input().split()]
d=[int(x) for x in input().split()]
e=[int(x) for x in input().split()]
f=[]
i=0
j=0
k=0
l=0
t=0
while i < len(d) and j < len(e):
  if d[i] < e[j]:
    f.append(d[i])
    i+=1
  else:
    f.append(e[j])
    j+=1
if i < len(d):
  f.extend(d[i:])
else:
  f.extend(e[j:])
while True:
  if k < len(f) and t+f[k] <= c:
    t+=f[k]
    k+=1
    l+=1
  else:
    break
print(l)

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()))
from collections import deque
A = A[::-1]
B = B[::-1]

time = 0
count = 0
while 1:
    if A and B:
        a, b = A.pop(), B.pop()
        if a > b:
            time += b
            if time > K:
                break
            count += 1
            A.append(a)
        else:
            time += a
            if time > K:
                break
            count += 1
            B.append(b)
    elif A and not B:
        a = A.pop()
        time += a
        if time > K:
            break
        count += 1
    elif not A and B:
        b = B.pop()
        time += a
        if time > K:
            break
        count += 1
    else:
        break
print(count)

Submission status: Wrong Answer

Solution code:
import sys


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    _, _, k = _ia()
    a = [k+1] + list(reversed(list(_ia())))
    b = [k+1] + list(reversed(list(_ia())))
    s = 0
    cnt = 0
    while s < k:
        ai = a.pop()
        bi = b.pop()
        if ai < bi:
            s += ai
            b.append(bi)
        else:
            s += bi
            a.append(ai)
        if s <= k:
            cnt += 1

    return cnt


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