Problem:


Score : 300 points

Problem Statement

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

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

Consider the following action:

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

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

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

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

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

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

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

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

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

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

Sample Output 3

0

Watch out for integer overflows.



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


Sample output:
3

Submission status: Runtime Error

Solution code:
n, m ,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = max(len(a), len(b))
ans, time = 0, 0

while k >= time:
    if a[0] <= b[0]:
        time += a[0]
        if k >= time:
            ans += 1
            del a[0]
        else:
            time -= a[0]
            break
    else:
        time += b[0]
        if k >= time:
            ans += 1
            del b[0]
        else:
            time -= b[0]
            break

print(ans)

Submission status: Runtime Error

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

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

s2 = [0]
for i in range(m):
    s2.append(s2[-1]+b[i])
ans = 0
for i in range(1,n):
    p = k-s1[i]
    j = 0
    while p-s2[j]>0:
        if p-s2[j]>0:
            p -= s2[j]
            j += 1
        else:
            break
    ans = max(i+j-1,ans)
print(ans)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using namespace std;
typedef long long ll;

int N, M;
ll K;
vector<ll> A;
vector<ll> B;

bool is_ok(vector<ll> B, int cnt_a, int mid){
  return A[cnt_a] + B[mid] <= K;
}

int binary_search(vector<ll> B, int cnt_a) {
    int left = -1; // 配列の左端
    int right = B.size(); // 配列の右端
    // 両端の差が1になるまで続ける
    while (right - left > 1){
        int mid = (right + left) / 2; // 区間の真ん中
        if (is_ok(B, cnt_a, mid)) left = mid;  // もし調べている対象が「is_okの条件」に当てはまればleftをmidまで移動
        else right = mid;  // 当てはまらなければrightをmid-1に移動
    }
    return left;
}

int main(){
  cin >> N >> M >> K;
  // 0インデックスには何も読まない0という初期値をそのまま入れておく
  A.push_back(0);
  B.push_back(0);

  rep(i, N){
    ll a;
    cin >> a;
    A.push_back(a);
  }
  rep(i, M){
    ll b;
    cin >> b;
    B.push_back(b);
  }

  rep(i, N) A[i+1] += A[i];
  rep(i, M) B[i+1] += B[i];

  int ans = 0;
  int cnt_b;
  rep(cnt_a, N+1){
    if (A[cnt_a] > K) continue;
    cnt_b = binary_search(B, cnt_a);
    ans = max(ans, cnt_a + cnt_b);
  }
  cout << ans << endl;
}

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

int main(int argc, char *argv[]) {

	long N,M; cin >> N >> M;
	long K; cin >> K;
	
	vector<long> A(N+1,0);
	for (int i = 1; i <= N; i++) {
		int a; cin >> a;
		A[i] = A[i-1] + a;
	}

	vector<long> B(M+1,0);
	for (int i = 1; i <= M; i++) {
		int b; cin >> b;
		B[i] = B[i-1] + b;
	}

	long ans = 0;
	long best = M;
	for (int i = 1; i <= N; i++) {
		if (A[i] > K) {
			break;	
		}
		
		while (1 < best and B[best] > K - A[i]) {
			best--;		
		}
		ans = max(ans, i+best);

	}
	cout << ans << endl;



	return 0;
}

Submission status: Runtime Error

Solution code:
from collections import deque

N, M, K = [int(n) for n in input().split()]
desk_a = deque([int(n) for n in input().split()])
desk_b = deque([int(n) for n in input().split()])

def max_n_book(desk_a, desk_b, count=0, k=K):
    if k < 0:
        return count - 1
    if len(desk_a) != 0:
        book_a = desk_a.popleft()
        count_a = max_n_book(desk_a, desk_b, count=count+1, k=k-book_a)
    else:
        count_a = count
    if len(desk_b) != 0:
        book_b = desk_b.popleft()
        count_b = max_n_book(desk_b, desk_b, count=count+1, k=k-book_b)
    else:
        count_b = count
    return max(count_a, count_b)

n_book = max_n_book(desk_a, desk_b, count=0, k=K)
print(n_book)

Submission status: Runtime Error

Solution code:
from collections import deque

N, M, K = [int(n) for n in input().split()]
desk_a = deque([int(n) for n in input().split()])
desk_b = deque([int(n) for n in input().split()])

def max_n_book(desk_a, desk_b, count=0, k=K):
    if k < 0:
        return count - 1
    if len(desk_a) != 0:
        book_a = desk_a.popleft()
        count_a = max_n_book(desk_a, desk_b, count=count+1, k=k-book_a)
        count_a = count
    else:
        count_a = count
    if len(desk_b) != 0:
        # book_b = desk_b.popleft()
        # count_b = max_n_book(desk_b, desk_b, count=count+1, k=k-book_b)
        count_b = count
    else:
        count_b = count
    return max(count_a, count_b)

n_book = max_n_book(desk_a, desk_b, count=0, k=K)
print(n_book)

Submission status: Runtime Error

Solution code:
from collections import deque

N, M, K = [int(n) for n in input().split()]
desk_a = deque([int(n) for n in input().split()], maxlen=200001)
desk_b = deque([int(n) for n in input().split()], maxlen=200001)

def max_n_book(desk_a, desk_b, count=0, k=K):
    if k < 0:
        return count - 1
    if len(desk_a) != 0:
        # book_a = desk_a.popleft()
        # count_a = max_n_book(desk_a, desk_b, count=count+1, k=k-book_a)
        count_a = 0
    else:
        count_a = count
    if len(desk_b) != 0:
        # book_b = desk_b.popleft()
        # count_b = max_n_book(desk_b, desk_b, count=count+1, k=k-book_b)
        count_a = 0
    else:
        count_b = count
    return max(count_a, count_b)

n_book = max_n_book(desk_a, desk_b, count=0, k=K)
print(n_book)

Submission status: Runtime Error

Solution code:
from collections import deque

N, M, K = [int(n) for n in input().split()]
desk_a = deque([int(n) for n in input().split()], maxlen=200001)
desk_b = deque([int(n) for n in input().split()], maxlen=200001)

def max_n_book(desk_a, desk_b, count=0, k=K):
    if k < 0:
        return count - 1
    if len(desk_a) != 0:
        book_a = desk_a.popleft()
        # count_a = max_n_book(desk_a, desk_b, count=count+1, k=k-book_a)
        count_a = 0
    else:
        count_a = count
    if len(desk_b) != 0:
        book_b = desk_b.popleft()
        # count_b = max_n_book(desk_b, desk_b, count=count+1, k=k-book_b)
        count_a = 0
    else:
        count_b = count
    return max(count_a, count_b)

n_book = max_n_book(desk_a, desk_b, count=0, k=K)
print(n_book)

Submission status: Runtime Error

Solution code:
from collections import deque

N, M, K = [int(n) for n in input().split()]
desk_a = deque([int(n) for n in input().split()], maxlen=200001)
desk_b = deque([int(n) for n in input().split()], maxlen=200001)

def max_n_book(desk_a, desk_b, count=0, k=K):
    if k < 0:
        return count - 1
    if len(desk_a) != 0:
        book_a = desk_a.popleft()
        count_a = max_n_book(desk_a, desk_b, count=count+1, k=k-book_a)
    else:
        count_a = count
    # if len(desk_b) != 0:
    #     book_b = desk_b.popleft()
    #     count_b = max_n_book(desk_b, desk_b, count=count+1, k=k-book_b)
    # else:
    #     count_b = count
    # return max(count_a, count_b)
    return count_a

n_book = max_n_book(desk_a, desk_b, count=0, k=K)
print(n_book)

Submission status: Runtime Error

Solution code:
from collections import deque

N, M, K = [int(n) for n in input().split()]
desk_a = deque([int(n) for n in input().split()], maxlen=200001)
desk_b = deque([int(n) for n in input().split()], maxlen=200001)

def max_n_book(desk_a, desk_b, count=0, k=K):
    if k < 0:
        return count - 1
    if len(desk_a) != 0:
        book_a = desk_a.popleft()
        count_a = max_n_book(desk_a, desk_b, count=count+1, k=k-book_a)
    else:
        count_a = count
    if len(desk_b) != 0:
        book_b = desk_b.popleft()
        count_b = max_n_book(desk_b, desk_b, count=count+1, k=k-book_b)
    else:
        count_b = count
    return max(count_a, count_b)

n_book = max_n_book(desk_a, desk_b, count=0, k=K)
print(n_book)

Submission status: Runtime Error

Solution code:
from collections import deque

N, M, K = [int(n) for n in input().split()]
desk_a = deque([int(n) for n in input().split()], maxlen=None)
desk_b = deque([int(n) for n in input().split()], maxlen=None)

def max_n_book(desk_a, desk_b, count=0, k=K):
    if k < 0:
        return count - 1
    if len(desk_a) != 0:
        book_a = desk_a.popleft()
        count_a = max_n_book(desk_a, desk_b, count=count+1, k=k-book_a)
    else:
        count_a = count
    if len(desk_b) != 0:
        book_b = desk_b.popleft()
        count_b = max_n_book(desk_b, desk_b, count=count+1, k=k-book_b)
    else:
        count_b = count
    return max(count_a, count_b)

n_book = max_n_book(desk_a, desk_b, count=0, k=K)
print(n_book)

Submission status: Runtime Error

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

a_, b_ = [0], [0]

for i in range(n):
    a_.append(a_[i] + a[i])
for i in range(n):
    b_.append(b_[i] + b[i])

ans, j = 0, m - 1

for i in range(n + 1):
    if a_[i] > k:
        break
    while b_[j] > k - a_[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod = 10 ** 9 + 7

N, M, K = LS()
desk = LSR(2)
a, b = [0], [0]

# a = [0, 0 + A1, 0 + A1 + A2, ....]
# b = [0, 0 + B1, 0 + B1 + B2, ....]
for i in range(N):
    a.append(a[i] + desk[0][i])
for j in range(M):
    b.append(b[j] + desk[1][j])

# a + b <= K を求める　⇒　変形してb >= K - a とすることで、
# aは全件トライ、bのみ選択可能な最大値を算出することで計算量をO(N + M)に抑える
ans, j = 0, M 

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

print(ans)

Submission status: Runtime Error

Solution code:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
asum = [0]*(n+1)
bsum = [0]*(m+1)
for i in range(n):
	asum[i+1] = a[i] + asum[i]
for j in range(m): 
	bsum[i+1] = b[j] + bsum[j]
j = m
res = 0
for i in range(n+1):
	if asum[i] > k:
		break
	while asum[i] + bsum[j] > k:
		j-=1
	res = max(res,i+j)
print(res)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

def sub(A,B,K,ai,bi):
    if K < 0:
        return 0
    cntA = 0
    if len(A) - (ai) > 0:
        cntA = sub(A, B, K-A[ai],ai+1, bi)
    cntB = 0
    if len(B) - (bi) > 0:
        cntB = sub(A, B, K-B[bi],ai, bi+1)
    return max(cntA,cntB) + 1

print(sub(A,B,K, 0, 0)-1)

Submission status: Runtime Error

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

def sub(A,B,K,ai,bi):
    if K < 0:
        return 0
    cntA = sub(A, B, K-A[ai],ai+1, bi) if len(A) - (ai) != 0 else 0
    cntB = sub(A, B, K-B[bi],ai, bi+1) if len(B) - (bi) != 0 else 0
    return max(cntA,cntB) + 1

print(sub(A,B,K, 0, 0)-1)

Submission status: Runtime Error

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

def sub(A,B,K,ai,bi):
    if K <= 0:
        return 0
    cntA = sub(A, B, K-A[ai],ai+1, bi) if len(A) - (ai) != 0 else 0
    cntB = sub(A, B, K-B[bi],ai, bi+1) if len(B) - (bi) != 0 else 0
    return max(cntA,cntB) + 1

print(sub(A,B,K, 0, 0)-1)

Submission status: Runtime Error

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

def sub(A,B,K):
    if K < 0:
        return 0
    cntA = sub(A[1:], B, K-A[0]) if len(A) != 0 else 0
    cntB = sub(A, B[1:], K-B[0]) if len(B) != 0 else 0
    #print(A,B,K, cntA, cntB)
    #print("A") if cntA > cntB else print("B")
    return max(cntA,cntB) + 1

print(sub(A,B,K)-1)

Submission status: Runtime Error

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

a = [0]
b = [0]
aa = 0
bb = 0
for i in A:
    aa += i
    a.append(aa)
for j in B:
    bb += j
    b.append(bb)

ans = 0
cnt = 0
lb = len(b)-1
for i in range(len(a)):
    cnt = a[i]
    if(cnt > K):
        break
    for j in reversed(range(lb)):
        tmp = cnt + b[j]
        if(tmp > K):
            lb = j
        else:
            ans = max(i+j, ans)
            break

print(ans)

Submission status: Runtime Error

Solution code:
 N, M, K = map(int, input().split())
2 A = list(map(int, input().split()))
3 B = list(map(int, input().split()))
4
5 a,b=[0],[0]
 6 for 7
8 for 9
i in range(N): a.append(a[i] + A[i]) i in range(M): b.append(b[i] + B[i])
10
11 ans,j=0,M
12 for 13
14
15
i in range(N + 1): ifa[i]>K:
break
while b[j] > K - a[i]:
j -= 1
ans = max(ans, i + j)
16
17
18 print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import numpy as np
def resolve():
    N,M,K = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))

    Amax_idx = N
    Asum = np.zeros(N+1, dtype = int)
    for i in range(1,N+1):
        Asum[i] = Asum[i-1] + A[i-1]
        if Asum[i] > K:
            Amax_idx = i - 1
            break

    ans = Amax_idx
    ansmax = ans
    anssum = Asum[Amax_idx]
    Acount = 0
    for i in range(M):
        anssum += B[i]
        while anssum > K:
            anssum -= A[Amax_idx - Acount]
            Acount += 1
            if Acount > Amax_idx:
                print(ansmax)
                return
            ans -= 1
        ans += 1  
        ansmax = max(ansmax,ans)
    print(ansmax)
resolve()

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
def resolve():
    N,M,K = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))

    Amax_idx = N
    Asum = np.zeros(N+1, dtype = int)
    for i in range(1,N+1):
        Asum[i] = Asum[i-1] + A[i-1]
        if Asum[i] > K:
            Amax_idx = i - 1
            break

    ans = Amax_idx
    ansmax = ans
    anssum = Asum[Amax_idx]
    Acount = 0
    for i in range(M):
        anssum += B[i]
        while anssum > K:
            anssum -= A[Amax_idx - Acount]
            Acount += 1
            if Acount < 0:
                print(ansmax)
                sys.exit()
            ans -= 1
        ans += 1  
        ansmax = max(ansmax,ans)
    print(ansmax)
resolve()

Submission status: Runtime Error

Solution code:
from collections import deque

N, M, K = map(int, input().split())
A = deque([int(x) for x in input().split()])
B = deque([int(x) for x in input().split()])
tsundoku = 0

while K > 0:
    if not A:
        K -= B.popleft()
    elif not B:
        K -= A.popleft()
    elif A[0] < B[0]:
        K -= A.popleft()
    elif A[0] > B[0]:
        K -= B.popleft()
    elif A[0] == A[0]:
        if A[1] < B[1]:
            K -= A.popleft()
        elif A[1] > B[1]:
            K -= B.popleft()

    if K >= 0:
        tsundoku += 1

print(tsundoku)

Submission status: Runtime Error

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
 
a,b = [0],[0]
p,ans = 0
 
for i in range(N):
  a.append(a[i]+A[i])
  if a[i] <= K:
    p = i
for i in range(M):
  b.append(b[i]+B[i])

for i in range(N+M+2):
  tmp = 0
  for j in range(max(0,i-M),min(N+1,i+1)):
    if a[j]+b[i-j] <= K:
      tmp = 1
      ans = i
      break
  if tmp == 0:
    break

print(ans)

Submission status: Runtime Error

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
 
a,b = [0],[0]
k,ans = 0
 
for i in range(N):
  a.append(a[i]+A[i])
  if a[i] <= K:
    k = i
for i in range(M):
  b.append(b[i]+B[i])

for i in range(k,N+M+2):
  tmp = 0
  for j in range(max(0,i-M),min(N+1,i+1)):
    if a[j]+b[i-j] <= K:
      tmp = 1
      ans = i
      break
  if tmp == 0:
    break

print(ans)

Submission status: Runtime Error

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
 
a,b = [0],[0]
ans = 0
 
for i in range(N):
  a.append(a[i]+A[i])
for i in range(M):
  b.append(b[i]+B[i])
  
for i in range(N+M+2):
  tmp = 0
  for j in range(min(N+1,i+1)):
    if i-j > M+1:
      continue
    if a[j]+b[i-j] < K:
      tmp = 1
      ans = i
      break
  if tmp == 0:
    break

print(ans)

Submission status: Runtime Error

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
 
a,b = [0],[0]
ans = 0
 
for i in range(N):
  a.append(a[i]+A[i])
for i in range(M):
  b.append(b[i]+B[i])
  
for i in range(N+M+2):
  tmp = 0
  for j in range(min(N+1,i+1)):
    if a[j]+b[i-j] < K:
      tmp = 1
      ans = i
      break
  if tmp == 0:
    break

print(ans)

Submission status: Runtime Error

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
 
sum = []
a,b = [0],[0]
ans = 0
 
for i in range(N):
  a.append(a[i]+A[i])
for i in range(M):
  b.append(b[i]+B[i])
  
for i in range(N+M+2):
  tmp = 0
  for j in range(i+1):
    if a[j]+b[i-j] < K:
      tmp = 1
      ans = i
      break
  if tmp == 0:
    break

print(ans)

Submission status: Runtime Error

Solution code:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
 
a,b = [0],[0]
ans = 0
 
for i in range(N):
  a.append(a[i]+A[i])
for i in range(M):
  b.append(b[i]+B[i])
  
for i in range(N+M+2):
  tmp = 0
  for j in range(i):
    if a[j]+b[i-j] < K:
      tmp = i+1
      ans = max(ans,i)
      break

print(ans)

Submission status: Runtime Error

Solution code:

N, M, X = map(int, input().split())
C = []
A = []
for  i in range(N):
    t = list(map(int, input().split()))
    C.append(t[0])
    A.append(t[1:])
    
result = -1
"""
<< bit演算に関する演算子
左辺の値を右辺の値だけ左へシフトすることを意味する

https://www.javadrive.jp/python/num/index4.html

下記の場合、1からNまで2真数でシフトしていく感じ
"""

for i in range(1 << N):
    #初期化
    t = [0] * M
    c = 0
    #print(i)
    for j in range(N):
        #print(j)
        if(i >> j ) & 1 == 0 :
            continue
        c += C[j]
        for k in range(M):
            t[k] += A[j][k]
    if all(x >= X for x in t):
        if result == -1:
            result = c
        else:
            result = min(result, c)
print(result)

Submission status: Runtime Error

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

time = 0
i,j = 0,0
ans = 0
while 1:

  if i == n and j == m :
    break

  if i == n:
    time += b[j]
    j += 1
  elif j == m:
    time += b[j]
    j += 1
  elif a[i] < b[j]:
    time += a[i]
    i += 1
  elif a[i] >= b[j]:
    time += b[j]
    j += 1

  if time > k:
    break
  else:
    ans += 1

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
import sys
 
n, m, k = map(int, sys.stdin.readline().split())
 
a = sys.stdin.readline()
b = sys.stdin.readline()
 
total = 0
 
a_cost, a = a.split(' ', 1)
b_cost, b = b.split(' ', 1)
 
while True:
  a_cost_int = int(a_cost)
  b_cost_int = int(b_cost)
  
  if a_cost_int > b_cost_int:
    new_total = total + b_cost_int
    b_cost, b = b.split(' ', 1)
  else:
    new_total = total + a_cost_int
    a_cost, a = b.split(' ', 1)
  
  if new_total > k:
    print(new_total)
    break
  else:
    total = new_total

Submission status: Runtime Error

Solution code:
import sys

n, m, k = map(int, sys.readline().split())

a = sys.readline()
b = sys.readline()

total = 0

a_cost, a = a.split(' ', 1)
b_cost, b = b.split(' ', 1)

while True:
  a_cost_int = int(a_cost)
  b_cost_int = int(b_cost)
  
  if a_cost_int > b_cost_int:
    new_total = total + b_cost_int
    b_cost, b = b.split(' ', 1)
  else:
    new_total = total + a_cost_int
    a_cost, a = b.split(' ', 1)
  
  if new_total > k:
    print(new_total)
    break
  else:
    total = new_total

Submission status: Runtime Error

Solution code:
import itertools
import math
import fractions
import functools
import copy
from collections import deque
from functools import reduce
from decimal import Decimal


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

    a_sum = []
    b_sum = []
    for i in range(1, len(a)+1):
        a_sum.append(sum(a[0:i]))
    for i in range(1, len(b)+1):
        b_sum.append(sum(b[0:i]))

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import itertools
import math
import fractions
import functools
import copy
from collections import deque
from functools import reduce
from decimal import Decimal


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

    a_sum = []
    b_sum = []
    for i in range(1, len(a)+1):
        a_sum.append(sum(a[0:i]))
    for i in range(1, len(b)+1):
        b_sum.append(sum(b[0:i]))

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
data = input().split(" ")
A = input().split(" ")
B = input().split(" ")
i = 0
j = 0
C = []
while (i == data[0]) and (j == data[1]):
  if i == data[0]:
    A[i] = 0
  if j == data[1]:
    B[j] = 0
    
  if A[i]<B[j]:
    C.append(A[i])
    i += 1
  else:
    C.append(B[j])
    j += 1
k = 0
l = 0
while data[2] >0:
  data[2] -= C[l]
  l += 1
  k += 1
print(k)

Submission status: Runtime Error

Solution code:
N, M, K = map(int, input().split())
time = 0
tmp = 0
countA = 0
countB = 0

tukue_A = list(map(int, input().split()))
tukue_B = list(map(int, input().split()))

while time <= K:
    if countA < N and tukue_A[countA] <= tukue_B[countB]:
        time += tukue_A[countA]
        countA += 1
        tmp += 1
        if time >= K:
            break
    else:
        time += tukue_B[countB]
        countB +=1
        tmp += 1
        if time >= K:
            break
print(tmp)

Submission status: Runtime Error

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

a = [0]
b = [0]

for i in range(n):
    a.append(a[i] + A[i])

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

asumlist = list([0])
asum = 0
for n in range(N):
  asum += alist[n]
  if K >=asum:
    asumlist.append(asum)
  else:
    break

bsumlist = list([0])
bsum = 0
for m in range(M):
  bsum += blist[m]
  if K >=bsum:
    bsumlist.append(bsum)
  else:
    break

max_b=0
for n in range(len(asumlist)):
  startm = 0
  if K>=asumlist[n] + bsumlist[int(len(bsumlist))]:
    startm=int(len(bsumlist))
  for m in range(len(bsumlist)):
    if K >= asumlist[n]+bsumlist[m]:
      b = n + m
      if max_b < b:
        max_b = b
    else:
      break
  else:
    b = n + len(bsumlist)-1
    if max_b < b:
      max_b = b
else:
  b = len(asumlist) + len(bsumlist)-2
  if asumlist[-1]+bsumlist[-1] <= K and max_b < b:
    max_b = b
print(max_b)

Submission status: Runtime Error

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

suma = [0] * n
sumb = [0] * m
suma[0] = a[0]
sumb[0] = b[0]

for i in range(1,n):
    suma[i] = suma[i-1]+a[i]
for j in range(1,m):
    sumb[j] = suma[j-1]+b[j]

    
ans, cur= 0, m-1
for i in range(n):
    target = k - suma[i]
    if (i > 0) & (target <= 0):
        break
    for j in range(cur,-1,-1):
        if sumb[j] <= target:
            ans = max(ans, i+j+2)
            cur = j
            break
        else:
          	ans = i+1
print(ans)

Submission status: Runtime Error

Solution code:
m,n,k=map(int,input().split())
s=[]
t=[]
s=list(map(int,input().split()))
t=list(map(int,input().split()))
i=0
j=0
f=0
c=0
while i<len(s) and j<len(t):
  if s[i]<=t[i]:
    if s[i]<=k:
      c+=1
      k-=s[i]
      s.remove(s[i])
    else:
      f=1
      break
  else:
    if t[j]<=k:
      c+=1
      k-=t[j]
      t.remove(t[j])
    else:
      f=1
      break
if f==1:
  print(c)
else:
  if s!=[]:
    i=0
    while i<len(s):
      if s[i]<=k:
        s.remove(s[i])
        c+=1
        k-=s[i]
      else:
        break
  elif t!=[]:
    i=0
    while i<len(t):
      if t[i]<=k:
        t.remove(t[i])
        k-=t[i]
        c+=1
      else:
        break
  print(c)

Submission status: Runtime Error

Solution code:
m,n,k=map(int(input()))
for i in range(m):
  s.append(int(input()))
for i in range(n):
  s.append(int(input()))  
i=0
j=0
f=0
while i<len(s) and j<len(t):
  if s[i]<=t[i]:
    if s[i]<=k:
      c+=1
      k-=s[i]
      s.remove(s[i])
    else:
      f=1
      break
  else:
    if t[j]<=k:
      c+=1
      k-=t[j]
      t.remove(t[j])
    else:
      f=1
      break
if f==1:
  print(c)
else:
  if s!=[]:
    i=0
    while i<len(s):
      if s[i]<=k:
        s.remove(s[i])
        c+=1
        k-=s[i]
      else:
        break
  elif t!=[]:
    i=0
    while i<len(t):
      if t[i]<=k:
        t.remove(t[i])
        k-=t[i]
        c+=1
      else:
        break
print(c)

Submission status: Runtime Error

Solution code:
nn= input().split()
N = int(nn[0])
M = int(nn[1])
K = int(nn[2])
MM = input().split()
LL = input().split()
total =0
count = -1
while total <= K :
  if len(MM) != 0:
    a =int(MM[0])
  else:
    a = 1000000000
  if len(LL) != 0:
    b =int(LL[0])
  else:
    b = 1000000000
  if a <= b:
    total +=a
    MM.pop(0)
  else:
    total +=b
    LL.pop(0)
  count +=1
print(count)

Submission status: Runtime Error

Solution code:
nn= input().split()
N = int(nn[0])
M = int(nn[1])
K = int(nn[2])
MM = input().split()
LL = input().split()
total =0
count = -1
while total <= K :
  if len(MM) != 0:
    a =int(MM[0])
  else:
    a = 1000000000
  if len(LL) != 0:
    b =int(LL[0])
  else:
    b = 1000000000
  if a <= b:
    total +=a
    MM.pop(0)
  else:
    total +=b
    LL.pop(0)
  count +=1
print(count)
print(total)