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
import math
import heapq
from collections import defaultdict, deque
input = sys.stdin.readline
def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

n,m,k=rm()
a=rl()
b=rl()
i=0;j=0;la=len(a);lb=len(b);cnt=0
while (i<la or j<lb) and k>0:
    if i==la:
        if b[j]<=k:
            cnt+=1
            k-=b[j]
            j+=1
        else:
            break
    elif j==lb:
        if a[i]<=k:
            cnt+=1
            k-=a[i]
            i+=1
        else:
            break
    elif a[i]<=b[j]:
        if a[i]<=k:
            k-=a[i]
            cnt+=1
            i+=1
        else:
            break
    else:
        if b[j]<=k:
            k-=b[j]
            cnt+=1
            j+=1
        else:
            break
print(cnt)

Submission status: Wrong Answer

Solution code:
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math
from collections import deque
import itertools
import heapq
#import bisect
from fractions import Fraction
import copy
from functools import lru_cache
from collections import defaultdict
import pprint

#oo=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
# ko=list("abcdefghijklmnopqrstuvwxyz")

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)

def soinsubunkai(n):
    a = []
    i = 1
    while i*i <= n:
        if n % i == 0 and i!=1:
            a.append(i)
            n=n//i

        if n% i !=0 or i==1:
            i += 1
    nokori=[n]
    return a + nokori


def main():
    n,m,k=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    maxcount=0
    totaltime=0
    maxa=0
    for i in range(n):
        if totaltime+a[i]<=k:
            totaltime+=a[i]
            maxcount+=1
        else:
            maxa=i-1
            break
    nowcount=maxcount
    for i in range(m):
        if totaltime+b[i]<=k:
            totaltime+=b[i]

            nowcount+=1
            maxcount=max(maxcount,nowcount)
        else:
            if maxa<0:
                break
            else:
                while maxa>=0:
                    if totaltime-a[maxa]+b[i]<=k:
                        totaltime=totaltime-a[maxa]+b[i]
                        maxa-=1
                        break
                    else:
                        if maxa>=1:
                            totaltime-=a[maxa]
                            maxa-=1
                            nowcount-=1

                        else:
                            break
    print(max(maxcount,nowcount))


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

time = 0
i = 0
j = 0
cnt = 0
a = A[i]
b = B[j]
while(time<K):
    if a<b :
        time += a
        i += 1
        if i >= N:
            a = 99999999999
        else:
            a = A[i]
    else :
        time += b
        j +=1
        if j >= M:
            b = 99999999999
        else:
            b = B[j]
    cnt += 1
    if cnt >=(N+M):
        break
    if time >= K:
        cnt -= 1
        break

print(cnt)

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

a = 0
b = 0
La = len(A)
Lb = len(B)
ans = 0
S = 0
while S <= K:
  if a == N:
    va = 10000000000000
  else:
    va = A[a]
  if b == M:
    vb = 10000000000000
  else:
    vb = B[b]
    
  if a  < b:
    a += 1
    S  += va
    ans += 1
  else:
    b += 1
    S += vb
    ans += 1
 
  
print(ans-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()))
ans=0
ati=[a[0]]
bti=[b[0]]
for i in range(1,n):
  ati.append(ati[i-1]+a[i])
for i in range(1,m):
  bti.append(bti[i-1]+b[i])
for i in range(n):
  for j in range(m):
    if ati[i]+bti[j]<=k:
      if i+j+2>ans:
        ans=i+j+2
    else:
      break
    
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def solve(A, B, K):
    N = len(A)
    M = len(B)
    count, t, ia, ib = 0, 0, 0, 0
    while t <= K:
        if ia < N and ib < M:
            if A[ia] <= B[ib]:
                t += A[ia]
                ia += 1
            else:
                t += B[ib]
                ib += 1
        else:
            if ia < N:
                t += A[ia]
                ia += 1
            if ib < M:
                t += B[ib]
                ib += 1
        if ia <= 0 and ib <= 0:
            break
        if t <= K:
            count += 1
    # print(ia, ib, count)
    return count

def main():
    from builtins import int, map
    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)
        exit()
    if A[0] > K or B[0] > K or A[0] + B[0] > K:
        print(0)
        exit()

    c1 = solve(A, B, K)
    c2 = solve(B, A, K)
    print(max(c1, c2))


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

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

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools as it
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    n,m,k = I2()
    a = Intl()
    b = Intl()
    t = 0
    i = 0
    j = 0
    cnt = 0
    while t <= k:
        #print(i,j,t)
        if i == n-1 and j == m-1:
            break
        elif i < n and j < m:
            if a[i] <= b[j]:
                t += a[i]
                i += 1
                if t <= k:
                    cnt += 1
            else:
                t += b[j]
                j += 1
                if t <= k:
                    cnt += 1 
        elif i >= n and j < m:
            t += b[j]
            j += 1
            if t <= k:
                cnt += 1 
        elif i < n and j >= m:
            t += a[i]
            i += 1
            if t <= k:
                cnt += 1
    print(cnt)

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()]
cont = 0
p,u = 0,0
while k>0 and p!=n and u != m:
    #if p == n-1 or u == m-1: break
    if a[p] <= b[u]:
        k-=a[p]
        if k<0: break
        p+=1
        cont+=1
    else:
        k-=b[u]
        if k<0: break
        u+=1
        cont+=1
    #print(k,p,u)
#beleza, agora acabou uma das estantes
if p == n:
    for i in range(u,m):
        k-=b[i]
        if k<0: break
        cont+=1
        
else:
    for i in range(p,n):
        k-=a[i]
        if k<0: break
        cont+=1
        

print(cont)

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
    c=0
    while True:
        if len(a)==0:
            if len(b)==0:
                if t>k:
                    c-=1
                break
            t+=b[0]
            c+=1
            b.pop(0)
            if t>k:
                c-=1
                break
            continue
        if len(b)==0:
            t+=a[0]
            c+=1
            a.pop(0)
            if len(a)==0:
                if t>k:
                    c-=1
                break
            continue
        if a[0]<b[0]:
            t+=a[0]
            a.pop(0)
            c+=1
        else:
            t+=b[0]
            b.pop(0)
            c+=1
        if t>k:#はみ出ているため
            c-=1
            break
    print(c)
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()))
number=0
s=0
while len(a)!=0 or len(b)!=0 :
  if len(a)==0 and len(b)==0:
    break
  elif len(a)==0:
    if s+b[0]<=k:
      number+=1
      s=s+b[0]
      b.pop(0)
    else:
      break
  elif len(b)==0:
    if s+a[0]<=k:
      number+=1
      s=s+a[0]
      a.pop(0)
    else:
      break
  elif a[0]<=b[0] and s+a[0]<=k:
    number+=1
    s=s+a[0]
    a.pop(0)
  elif a[0]>b[0] and s+b[0]<=k:
    number+=1
    s=s+b[0]
    b.pop(0)
  else:
    break
print(number)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right as br


def main():
    n, m, k = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    tmp = 0
    a = 0
    b = 0
    Sb = [B[0]]
    for i in range(1, m):
        Sb.append(Sb[-1] + B[i])
    Sa = [A[0]]
    for i in range(1, n):
        Sa.append(Sa[-1] + A[i])
    mx = 0
    for j in range(n):
        index = br(Sb, k - Sa[j]) - 1
        tmp = Sa[j] + Sb[index] if index > 0 else Sa[j]
        if tmp <= k:
            mx = max(mx, j + 1 + min(index + 1, m))
    print(mx)
    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()))
Alen=N
Blen=M
cnt=0

for i in range(N+M):
  if len(A)!=0 and len(B)!=0:
    if A[0]<=B[0] and K>=A[0]:
      K-=A[0]
      del A[0]
      cnt+=1
      #print(A)
    elif A[0]>B[0] and K>=B[0]:
      K-=B[0]
      del B[0]
      cnt+=1
      #print(B)
    else:
      flag=0
  elif len(A)==0 and len(B)!=0:
    if K>=B[0]:
      K-=B[0]
      del B[0]
      cnt+=1
      #print(B)
    else:
      flag=0
  elif len(A)!=0 and len(B)==0:
    if K>=A[0]:
      K-=A[0]
      del A[0]
      cnt+=1
      #print(A)
    else:
      flag=0
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()))
count = 0
ans = 0

for i in range(n + m):
    if a == []:
        if ans + b[0] <= k:
            ans += b[0]
            count += 1
            del(b[0])
    elif b == []:
        if ans + a[0] <= k:
            ans += a[0]
            count += 1
            del(a[0])

    elif a != [] and b != []:
        if ans + min(a[0], b[0]) <= k:
            ans += min(a[0], b[0])
            count += 1
            if a[0] == min(a[0], b[0]):
                del(a[0])
            else:
                del(b[0])

print(count)

Submission status: Wrong Answer

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

A = [i for i in map(int, input().split())]+[10**10]
B = [i for i in map(int, input().split())]+[10**10]

ans = 0
a = 0
b = 0
t = 0
# af = True
# bf = True

while 1:
    if A[a] == 10**10 and B[b] == 10**10:
        break

    if A[a] >= B[b] and t+B[b] <= K:
        t += B[b]
        b += 1
        # if b == len(B):
        #     bf = False
        ans += 1
    elif t+A[a] <= K:
        t += A[a]
        a += 1
        # if a == len(A):
        #     af = False

        ans += 1
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import copy
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_check = copy.deepcopy(A)
B_check = copy.deepcopy(B)

count = 0
book = 0
while True:
  if len(A) == len(B) == 0:
    break
  elif len(A) == 0:
    count += B[0]
    B.pop(0)
  elif len(B) == 0:
    count += A[0]
    A.pop(0)
  else:
    if A[0] < B[0]:
      count += A[0]
      A.pop(0)
    elif A[0] > B[0]:
      count += B[0]
      B.pop(0)
    elif A[0] == B[0]:
      if len(A) == 1:
        count += B[0]
        B.pop(0)
      elif len(B) == 1:
        count += A[0]
        A.pop(0)
      else:
        if A[1] < B[1]:
          count += A[0]
          A.pop(0)
        elif A[1] > B[1]:
          count += B[0]
          B.pop(0)
  if count > K:
    break
  book += 1

for i in range(len(A_check)):
  if A_check[i] > 1000000000:
    book = 0
for i in range(len(B_check)):
  if B_check[i] > 1000000000:
    book = 0
if N > 200000:
  book = 0
if M > 200000:
  book = 0
if K > 1000000000:
  book = 0

print(book)

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
t = 0

while True:
    if Ai < N and Bi < M:
        if A[Ai] <= B[Bi]:
            if t + A[Ai] <= K:
                t += A[Ai]
                Ai += 1
            else:
                break
        else:
            if t + B[Bi] <= K:
                t += B[Bi]
                Bi += 1
            else:
                break

    elif Ai >= N and Bi >= M:
        break
    elif Ai < N:
        if t + A[Ai] <= K:
            t += A[Ai]
            Ai += 1
        else:
            break
    else:
        if t + B[Bi] <= K:
            t += B[Bi]
            Bi += 1
        else:
            break

print(Ai+Bi)

Submission status: Wrong Answer

Solution code:
N,M,K=map(int,input().split())
a=input().split()
A=[int(c) for c in a]
b=input().split()
B=[int(c) for c in b]
answer=0
numbers=[]
a=0
b=0
while a<N and b<M:
    if A[a]>=B[b]:
        numbers.append(B[b])
        b+=1
    else:
        numbers.append(A[a])
        a+=1

if a<N:
    for a in A:
        numbers.append(a)
else:
    for b in B:
        numbers.append(b)
whole=0
for a in range(N+M):
    whole+=numbers[a]
    if whole<=K:
        answer+=1
print(answer)

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

i, j = 0, 0
readed = 0
count = 0

while True:
    if i >= n:
        if j >= m:
            break
        else:
            readed += b[j]
            j += 1
    elif j >= m:
        readed += a[i]
        i += 1
    elif a[i] < b[j]:
        readed += a[i]
        i += 1
    elif a[i] == b[j]:
        if i+1 >= n:
            if j+1 >= m:
                readed += a[i]
                i += 1
            else:
                readed += b[j]
                j += 1
        else:
            if j+1 >= m:
                readed += a[i]
                i += 1
            else:
                if a[i+1] <= b[j+1]:
                    readed += a[i]
                    i += 1
                else:
                    readed += b[j]
                    j += 1
    else:
        readed += b[j]
        j += 1
    if readed > k:
        break
    print(readed)
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
m,n,k=map(int,input().split())
l=list(map(int,input().split()))
li=list(map(int,input().split()))
z=0
ans=0
while(True):
  l1=len(l)
  l2=len(li)
  if l1>0 and l2>0:
    if l[0]>li[0]:
      z+=li[0]
      li.pop(0)
    else:
      z+=l[0]
      l.pop(0)
  elif l1==0 and l2>0:
    z+=li[0]
    li.pop(0)
  elif l1>0 and l2==0:
    z+=l[0]
    l.pop(0)
  else:
    break
  if z<=k:
    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()))
result = 0

A.append(10**10)
B.append(10**10)
while K >= 0:
    result += 1
    K = K - min(A[0],B[0])
    if A[0] <= B[0]:
        del A[0]
    else:
        del B[0]
result -= 1 
print(result)

Submission status: Wrong Answer

Solution code:
import bisect
from itertools import accumulate

n, m, k = map(int, input().split())
a = tuple(accumulate(map(int, input().split())))
b = tuple(accumulate(map(int, input().split())))
s = 0

cnt = 0
for i, j in enumerate(a):
    s += j
    if j <= k:
        cnt = max(cnt, i + bisect.bisect_right(b, k - s) + 2)
print(cnt)

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

tot = 0
count = 0

while A or B:
    count += 1
    if not B:
        tot += A.pop(0)
        if tot > K:
            count -= 1
            break
    elif not A:
        tot += B.pop(0)
        if tot > K:
            count -= 1
            break
    elif A[0] <= B[0]:
        tot += A.pop(0)
        if tot > K:
            count -= 1
            break
    else:
        tot += B.pop(0)
        if tot > K:
            count -= 1
            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()))

ans = 0
Sum = 0
i = 0
j = 0

while Sum <= K and (i != N and j != M):
  if A[i] < B[j]:
    Sum += A[i]
    ans += 1
    i += 1
    if i == N and Sum <= K:
      while Sum <= K and j < M:
        Sum += B[j]
        ans += 1
        j += 1
          
  else:
    Sum += B[j]
    ans += 1
    j += 1
    if j == M and Sum <= K:
      while Sum <= K and i < N:
        Sum += A[i]
        ans += 1
        i += 1

if Sum <= K:
  print(ans)
else:
  print(ans-1)

Submission status: Wrong Answer

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

ans=0
now=0
acnt=0
bcnt=0
for i in range(n):
    if now+a[i]<=k:
        now+=a[i]
        acnt+=1
for i in range(m):
    if now+b[i]<=k:
        now+=b[bcnt]
        bcnt+=1
ans=acnt+bcnt

tmp=acnt
for i in range(tmp):
    now-=a[tmp-i-1]
    acnt-=1
    # print(a[acnt-i-1],a[tmp-i-1],now)
    while bcnt!=m and now+b[bcnt]<=k:
        now+=b[bcnt]
        bcnt+=1
    ans=max(ans,acnt+bcnt)
    # print(now,bcnt)
for i in range(n):
    if now+a[i]<=k:
        now+=a[i]
        acnt+=1
ans=max(ans,acnt+bcnt)
tmp=bcnt


print(ans)

Submission status: Wrong Answer

Solution code:
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.append(100000000000000000)
B.append(100000000000000000)
A.reverse()
B.reverse()


ans = 0
c = 0
while True:
  if A[-1] > B[-1]:
    b = B.pop()
    if ans+b > X:
      break
    ans += b
    c += 1
  else:
    a = A.pop()
    if ans+a > X:
      break
    ans += a
    c += 1
print(c)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

x = deque(a)
y = deque(b)

ans=0
for i in range(n + m):
    # print(x, y)
    try:
        temp = x.popleft() if x[0] <= y[0] else y.popleft()
    except:
        if len(x) == 0:
            temp = y.popleft()
        elif len(y) == 0:
            temp=x.popleft()

    # print(k)
    k -= int(temp)
    if k >= 0:
        ans += 1
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
print("時間いっぱい読む")

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
while k>=0:
    if len(a)==0 and len(b)!=0:
        if k>=b[0]:
            ans+=1
            k-=b[0]
            del b[0]
        else:
            break
    elif len(a)!=0 and len(b)==0:
        if k>=a[0]:
            ans+=1
            k-=a[0]
            del a[0]
        else:
            break
    elif len(a)==0 and len(b)==0:
        break
    else:
        mi=min(a[0],b[0])
        if mi>k:
            break
        ans+=1
        k-=mi
        if a[0]>b[0]:
            del b[0]
        elif a[0]<b[0]:
            del a[0]
        else:
            if len(a)==1:
                del b[0]
            elif len(b)==1:
                del a[0]
            else:
                if a[1]>=b[1]:
                    del b[0]
                else:
                    del a[0]
print(ans)

Submission status: Wrong Answer

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

A = []
B = []

tmp = 0
for i in AStr:
    tmp += int(i)
    if (tmp > K):
        break
    A.append(int(i))

tmp = 0
for i in BStr:
    tmp += int(i)
    if (tmp > K):
        break
    B.append(int(i))

num = 0
tmp = 0
maxNum = len(A)
if maxNum < len(B):
    maxNum = len(B)


for i in range(len(A)):
    num = 0
    tmp = 0
    for j in range(i+1):
        tmp += A[j]
        num += 1
    for k in B:
        tmp += k
        if (tmp > K):
            if maxNum < num:
                maxNum = num
            continue
        num += 1

print(num)

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

S=sorted(A+B)
#print(S)
p=0;q=0
for i in range(len(S)):
  if (p+S[i])<=K:
    p=p+S[i]
    q=q+1
  else:
    break
print(q)

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
time = 0
n = 0
m = 0
while time <= K:
    if n < N and m < M and A[n] <= B[m]:
        if time + A[n] > K:
            break
        else:
            time += A[n]
            n += 1
            ans += 1
    elif n < N and m < M and B[m] <= A[n]:
        if time + B[m] > K:
            break
        else:
            time += B[m]
            m += 1
            ans += 1
    elif n < N and m == M :
        if time + A[n] > K:
            break
        else:
            time += A[n]
            n += 1
            ans += 1
    elif m < M and n == N:
        if time + B[m] > K:
            break
        else:
            time += B[m]
            m += 1
            ans += 1
    elif m == M and n == N:
        break
    #print(m, n, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
def _main(N, M, K, A, B):
    sum_k = 0.0
    a_index = 0
    a_len = len(A)
    b_index = 0
    b_len = len(B)
    while sum_k < K:
        current_a = A[a_index] if a_index < a_len else None
        current_b = B[b_index] if b_index < b_len else None
        if current_a is None and current_b is None:
            break

        if current_a is not None and current_b is None:
            if K < sum_k + current_a:
                break
            sum_k += current_a
            a_index += 1
        elif current_a is None and current_b is not None:
            if K < sum_k + current_b:
                break
            sum_k += current_b
            b_index += 1
        elif current_a < current_b:
            if K < sum_k + current_a:
                break
            sum_k += current_a
            a_index += 1
        else:
            if K < sum_k + current_b:
                break
            sum_k += current_b
            b_index += 1

    print(a_index + b_index)


if __name__ == "__main__":
    Na, Ma, Ka = map(int, input().split())
    Aa = list(map(float, input().split()))
    Ba = list(map(float, input().split()))
    _main(Na, Ma, Ka, Aa, Ba)

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 = 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 += b
        if time > K:
            break
        count += 1
    else:
        break
print(count)

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

time = 0
a_cnt = 0
b_cnt = 0
disp = False
for _ in range(n+m):
    if a_cnt<n and b_cnt<m:
        if a[a_cnt]>b[b_cnt]:
            time += b[b_cnt]
            b_cnt += 1
        else:
            time += a[a_cnt]
            a_cnt += 1
    elif a_cnt>=n:
            time += b[b_cnt]
            b_cnt += 1
    elif b_cnt>=m:
            time += a[a_cnt]
            a_cnt += 1
    
    if time == k:
        print(a_cnt+b_cnt)
        disp = True
        break
    elif time > k:
        print(a_cnt+b_cnt-1)
        disp = True
        break

if disp == False:
    print(a_cnt+b_cnt)

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

count = 0
for i in range(N + M):
  if len(A) == 0:
    book = B[0]
    B.popleft()
  elif len(B) == 0:
    book = A[0]
    A.popleft()
  else:
    if A[0] <= B[0]:
      book = A[0]
      A.popleft()
    else:
      book = B[0]
      B.popleft()
  
  count += 1
  K -= book
  if K <= 0:
    break

if K < 0:
  count -= 1

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())))
read_time = 0
cnt = 0
while a or b:
    if not a:
        read_time += b.popleft()
        if read_time > k:
            break
        cnt += 1
    elif not b:
        read_time += a.popleft()
        if read_time > k:
            break
        cnt += 1
    else:
        if a[0] <= b[0]:
            read_time += a.popleft()
            if read_time > k:
                break
            cnt += 1
        elif a[0] > b[0]:
            read_time += b.popleft()
            if read_time > k:
                break
            cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:


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

     BIG = pow(10,9) + 1

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


     times = 0
     read_books = 0

     while times < K:
         if A[0]+times > K and B[0]+times > K:
             break

         if A[0] < B[0]:
             times += A[0]

             if len(A) <= 1:
                 A[0] = BIG
             else:
                 x = A.pop(0)


         elif A[0] >= B[0]:
             times += B[0]

             if len(B) <= 1:
                 B[0] = BIG
             else:
                 x = B.pop(0)
         elif A[0] == BIG and B[0] == BIG:
             break
         else:
             op = 0
             # print("error?")

         read_books += 1

         # print("times {} read {}".format(times,read_books))



     print(read_books)






if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ct=0
sm=0
i=j=0

while (i+j)<(n+m) and sm<k:
  if i<n and j<m and l[i]<ll[j] :
    sm+=l[i]
    i+=1
  elif j<m and i<n and l[i]>=ll[j] :
    sm+=ll[j]
    j+=1
  elif i==n and j<m: 
    sm+=ll[j]
    j+=1
  elif i<n:
    sm+=l[i]
    i+=1
if sm>k:
  print(i+j-1)
else:
  print(i+j)