Problem:


Score : 200 points

Problem Statement

There are N gems. The value of the i-th gem is V_i.

You will choose some of these gems, possibly all or none, and get them.

However, you need to pay a cost of C_i to get the i-th gem.

Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.

Find the maximum possible value of X-Y.

Constraints

All values in input are integers.

1 \leq N \leq 20

1 \leq C_i, V_i \leq 50

Input

Input is given from Standard Input in the following format:

N
V_1 V_2 ... V_N
C_1 C_2 ... C_N

Output

Print the maximum possible value of X-Y.

Sample Input 1

3
10 2 5
6 3 4

Sample Output 1

5

If we choose the first and third gems, X = 10 + 5 = 15 and Y = 6 + 4 = 10.
We have X-Y = 5 here, which is the maximum possible value.

Sample Input 2

4
13 21 6 19
11 30 6 15

Sample Output 2

6

Sample Input 3

1
1
50

Sample Output 3

0



Sample input:
3
10 2 5
6 3 4


Sample output:
5

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    V = list(map(int, input().split()))
    C = list(map(int, input().split()))
    maxi = 0
    for i in range(2 ** N):
        binary = list(map(int, format(i, 'b').zfill(N)))
        ans = 0
        for j, k in enumerate(binary):
            if k == 1:
                ans += V[j] - C[j]
        if ans > maxi:
            maxi = ans

    print(maxi)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n= int(input())

v = list(map(int,input().split()))
c = list(map(int,input().split()))


x_y = 0
for i in range(2**n):

    tmp_x_y = 0
    tmp_cost=0
    tmp_value=0

    for j in range(n):
        if (i>>j) &1:
            tmp_cost+=c[j]
            tmp_value+=v[j]

    tmp_x_y = tmp_value - tmp_cost

    x_y = max(x_y,tmp_x_y)

print(x_y)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
V=list(map(int,input().split()))
C=list(map(int,input().split()))
ans=0
#宝石を取る取らない
def dfs(A):
    global ans
    # 終端条件 --- N 重ループまで回したら処理して打ち切り
    if len(A) == N:
        D=jg(A)
        if ans<D:
          ans=D
        return
    for v in range(2):
        A.append(v)
        dfs(A)
        A.pop()

#コスト算出
def jg(A):
  X=0
  Y=0
  for i in range(N):
    if A[i]==1:
      X+=V[i]
      Y+=C[i]
  d=X-Y
  return d
dfs([])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

diff =[V[n] - C[n] for n in range(N)]
XY = 0

for v in itertools.permutations([0, 1] * N, N):
  xy = 0
  for n in range(N):
    xy += diff[n] * v[n]
  if xy > XY:
    XY = xy
print(XY)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

diff =[V[n] - C[n] for n in range(N)]
XY = 0

for v in itertools.permutations([0, 1] * N, N):
  xy = 0
  for n in range(N):
    xy += diff[n] * v[n]
    if xy > XY:
      XY = xy
print(XY)

Submission status: Time Limit Exceeded

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict(list)
#import bisect
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    V = readInts()
    C = readInts()
    ans = -1
    for bit in range(1 << n):
        # bit 全探索
        cost = 0
        value = 0
        for i in range(n):
            if bit & (1 << i):
                # もしフラグが立っていたら、
                cost += C[i]
                value += V[i]
        ans = max(ans,value - cost)
    print(ans)
if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
icase=0
if icase==0:
    n=int(input())
    v=list(map(int,input().split()))
    c=list(map(int,input().split()))
    tmax=0
    for i in range(2 ** n):
        total = 0
        for j in range(n):  # このループが一番のポイント
            if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
                total = total+v[j]-c[j]  # 買い物累計額にも加算
        tmax=max(total,tmax)
    print(tmax)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

from itertools import product
status = [(0, 1) for _ in range(N)]
cases = list(product(*status))

max_v = 0
for case in cases:
	X, Y = 0, 0
	for i, s in enumerate(case):
		if s == 0:
			continue
		X += V[i]
		Y += C[i]
	max_v = max(max_v, X-Y)
	
print(max_v)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0

for i in range(1, 2**N):
    comb = list(map(int, bin(i)[2:].zfill(N)))
    X, Y = 0, 0
    for i, c in enumerate(comb):
        if c == 1:
            X += V[i]
            Y += C[i]
    ans = max(ans, X-Y)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
V = list(map(int,input().split()))
C = list(map(int,input().split()))

ans = 0
for i in range(2**N):
    X=0
    Y=0
    for j in range(N):
        if((i>>j)&1):
            X+=V[j]
            Y+=C[j]
        if X-Y>ans:
            ans = X-Y
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
V = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

ans = 0
for i in range(2 ** N):
    tmp = 0
    for j in range(N):
        if (i >> j) & 1:
            tmp += V[j] - C[j]
    ans = max(ans, tmp)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))

ans = 0

for i in range(0, 1<<n):
    x = 0
    y = 0
    for j in range(n):
        if(i>>j&1):
            x = x + v[j]
            y = y + c[j]
    
    if(ans < x-y):
        ans = x - y

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

import itertools
bit = list(itertools.product([0,1], repeat=n))

ans = []
for i in range(2 ** n):
    arr = list(bit[i])
    x = 0
    y = 0
    for j in range(len(arr)):
        if arr[j] == 1:
            x += v[j]
            y += c[j]
    ans.append(x-y)
print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
for i in range(2**n):
    # test = []
    X, Y = 0, 0
    for j in range(n):
        if (i >> j) & 1 == 1:
            X += v[j]
            Y += c[j]
            # test.append([v[j], c[j]])
    if ans < X - Y:
        ans = X - Y
    # print(test)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

a = list(product([0, 1], repeat=n))
m = 0
xsum = 0
ysum = 0

for i in range(len(a)):
    for j in range(n):
        if a[i][j] == 1:
            xsum += v[j]
            ysum += c[j]
    difxy = xsum - ysum
    if difxy > m:
        m = difxy
    xsum = 0
    ysum = 0

print(m)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product as p

N = int(input())
*V, = map(int, input().split())
*C, = map(int, input().split())

ans = 0
for a in p(range(2), repeat=N):
    X, Y = 0, 0
    for i, j in enumerate(a):
        if j:
            X+=V[i]
            Y+=C[i]
    ans = max(ans, X-Y)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N=int(input())
V=np.array(list(map(int,input().split())))
C=np.array(list(map(int,input().split())))
bit=[]
max=0
for i in range(2**N):
    bit=np.array([int(bin((i & (1 << j)) >> j), 0)  for j in range(N)])
    X=np.dot(V,bit)
    Y=np.dot(C,bit)
    if max<X-Y:
        max=X-Y
print(max)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))
bit = 0b0

ans = 0
for i in range(2**n):
    bag = []
    cost = []
    for j in range(n):
        if(((bit >> j) & 1) == 1):
            bag.append(v[j])
            cost.append(c[j])
        else:
            bag.append(0)
            cost.append(0)
    p = sum(bag) - sum(cost)
    if(p > ans):
        ans = p
    bit += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:

N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = []
for i in range(0, 2 ** N):
    x = 1
    a = 0
    for n in range(N):
        if i & x:
            a += V[n] - C[n]
        x = x << 1
    ans.append(a)
print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = -1e9
for i in range(2**n):
    conv = str(bin(i))[2:].zfill(n)
    val = 0
    for j in range(n):
        if conv[j] == "1":
            val += v[j] - c[j]
    ans = max(ans, val)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
v=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=0
for i in range(2**n):
	bit_i=bin(i)[2:].zfill(n)
	vi=0
	ci=0
	for j in range(len(bit_i)):
		if(bit_i[j]=='1'):
			vi+=v[j]
			ci+=c[j]
	if(ans < vi-ci):
		ans=vi-ci
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
ans = 0
for t in range(1, n):
    from itertools import combinations
    a = list(combinations(range(n), t))
    for i in range(len(a)):
        tmp = 0
        for j in a[i]:
            tmp += v[j] - c[j]
        ans = max(ans, tmp)
print(ans)
'''
ans = 0
for i in range(n):
    tmp = v[i] - c[i]
    if tmp > 0:
        ans += tmp
print(ans)
'''

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
ans = 0
for t in range(1, n):
    from itertools import permutations
    a = list(permutations(range(n), t))
    for i in range(len(a)):
        tmp = 0
        for j in a[i]:
            tmp += v[j] - c[j]
        ans = max(ans, tmp)
print(ans)
'''
ans = 0
for i in range(n):
    tmp = v[i] - c[i]
    if tmp > 0:
        ans += tmp
print(ans)
'''

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
v=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]
dif=[]
for i in range(n):
  if v[i]>c[i]:
    dif.append(v[i]-c[i])

ans=0
for i in range(1 << len(dif)):
    sum=0
    for j in range(len(dif)):
        if ((i>>j)&1)==1:
            sum += dif[j]
    ans = max(ans, sum)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
v=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]
ans=0
for i in range(1 << n):
    sum=0
    for j in range(n):
        if ((i>>j)&1)==1:
            sum += v[j] - c[j]
    ans = max(ans, sum)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
v=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]
b_lst=[]
for i in range(1 << n):
    sum_v=0
    sum_c=0
    for j in range(n):
        if ((i>>j)&1)==1:
            sum_v += v[j]
            sum_c += c[j]
    b_lst.append(sum_v - sum_c)
print(max(b_lst))

Submission status: Time Limit Exceeded

Solution code:
import itertools as it

N = int(input())
V = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

ans = 0
for ith_conf in it.product(range(2), repeat=N):
    dif = 0
    for j_jewel in range(N):
        if ith_conf[j_jewel] == 1:
            dif += V[j_jewel] - C[j_jewel]
    ans = max(ans, dif)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
for i in range(2**n):
  x = []
  y = []
  for j in range(n):
    if (i>>j) & 1:
      x.append(v[n - j - 1])
      y.append(c[n - j - 1])
  ans = max(ans,sum(x) - sum(y))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
indices = range(n)
l = []
for i in range(1 << n):
  l.append([indices[j] for j in range(n) if (i & (1 << j))])
l.pop(0)#[]
#c.index()
max_diff = 0
for s in l:
  cost = 0
  value = 0
  for i in s:
    cost += c[i]
    value += v[i]
    if value - cost > max_diff:
      max_diff = value - cost
print(max_diff)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
xy_l = []
for i in range(1 << N):
    xy = 0
    for j in range(N):
        if (i >> j) & 1:
            xy += V[j] - C[j]
    xy_l.append(xy)
print(max(xy_l))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

ma = 0
for i in range(2**n):
	a = bin(i)
	if len(a) < n+2:
		b = "0" * (n+2-len(a))
		a = a[:2] + b + a[2:]
	get = 0
	pay = 0
	for j in range(n):
		if a[j+2] == '1':
			get += v[j]
			pay += c[j]
	if ma < (get - pay):
		ma = (get - pay)

print(ma)

Submission status: Time Limit Exceeded

Solution code:
import sys
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    VS = list(map(int, input().split()))
    CS = list(map(int, input().split()))

    ans = 0
    for bit in range(2**N):
        tmp = 0
        for i in range(N):
            if bit & 1<<i == 0: continue
            tmp += VS[i] - CS[i]
        ans = max(ans, tmp)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

V_C = []
diff = 0

for i in range(N):
    V_C.append([V[i], C[i]])

for i in range(1, N+1):
    combs = list(combinations(V_C, i))
    for comb in combs:
        price = 0
        cost = 0
        for c in comb:
            price += c[0]
            cost += c[1]
            p_c = price - cost
            if p_c > diff:
                diff = p_c

print(diff)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
v=list(map(int,input().split()))
c=list(map(int,input().split()))
sum=0
i=0
while i<n:
  if v[i]>c[i]:
    sum+=v[i]-c[i]
    i+=1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
v=list(map(int,input().split()))
c=list(map(int,input().split()))
sum=0
i=0
while i<n:
  if v[i]>c[i]:
    sum+=v[i]-c[i]
print(sum)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
vs = list(map(int, input().split()))
cs = list(map(int, input().split()))

ret = - float('inf')
for i in range((2 ** n)):
    total_cost = 0
    total_value = 0
    j = 0
    while i > 0:
        if i & 1:
            total_cost += cs[j]
            total_value += vs[j]
        i >>= 1
        j += 1
    ret = max(ret, total_value - total_cost)
print(ret)

Submission status: Time Limit Exceeded

Solution code:
def weight( n, lst ):
    l = len(lst)
    wei = 0
    for i in range(N):
        if n % 2 == 1:
            wei += lst[l-i-1] 
        n  = n // 2
    return wei

N = int(input())
Vlist = list(map(int,input().split()))
Clist = list(map(int,input().split()))

maxval = 0
for i in range(2 ** N):
    vsum = weight(i,Vlist)
    csum = weight(i,Clist)
    gain = vsum - csum
    if i == 0:
        maxval = gain
    else:
        if maxval < gain:
            maxval = gain

print(maxval)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))

max_z = 0
for i in range(2**n):
  #print("i:",i)
  x = 0
  y = 0
  for j in range(n):
    if i&(1<<j)!=0:
      #print('j:',j)
      x+=v[j]
      y+=c[j]
  z=x-y
  #print(z)
  max_z = max(max_z,z)
print(max_z)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N = int(input())
V = list(map(int,input().split()))
C = list(map(int,input().split()))

num = list(range(N))
pmax = 0

for i in range(N):
    combi = list(combinations(num,i))
    for j in range(len(combi)):
        v_value = 0
        c_value = 0
        for k in range(len(combi[j])):
            v_value = v_value + V[combi[j][k]]
            c_value = c_value + C[combi[j][k]]
            pmax = max(pmax,v_value-c_value)
 
print(pmax)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
lst = []

for i in range(N):
	if V[i] > C[i]:
		lst.append(V[i] - C[i])
N = len(lst)
  
high_score = 0

if N > 0:

	  
	for i in range(2 ** N):
		a = list(str(bin(i))[2:])
		for k in range(N - len(a)):
			a.insert(0, "0")
		b = list(map(int, a))
		score = 0
		for j in range(len(b)):
			score += lst[j] * b[j]
		if high_score < score:
			high_score = score
		
print(high_score)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
lst = []

for i in range(N):
	lst.append(V[i] - C[i])
  
high_score = 0
  
for i in range(2 ** N):
	a = list(str(bin(i))[2:])
	for k in range(N - len(a)):
		a.insert(0, "0")
	b = list(map(int, a))
	score = 0
	for j in range(len(b)):
		score += lst[j] * b[j]
	if high_score < score:
		high_score = score
    
print(high_score)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
value = list(map(int, input().split()))
cost = list(map(int, input().split()))
tmp = 0
for p in range(2**n):
    profit = 0
    for j in range(n):
        if((p >> j) & 1):
            profit += (value[j] - cost[j])
    if profit > tmp:
        tmp = profit
print(tmp)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

length = len(V)
conb = []
for i in range(length+1):
    conb.append(list(itertools.combinations(V,i)))

cost = []
for c in conb:
    for i in c:
        idx = []
        x = 0
        y = 0
        for k in i:
            idx.append(V.index(k))
        for a in idx:
            x += V[a]
            y += C[a]
        cost.append(x-y)

print(max(cost))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
V = list(map(int,input().split()))
C = list(map(int,input().split()))

ans = []
n = N
for i in range(2 ** n):
    cost,value = 0,0
    for i1 in range(n):
        if ((i >> i1) & 1):
             cost += C[i1]
             value += V[i1]
    ans.append(value-cost)

print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
N = 0
V = []
C = []
 
i = 0
ans = 0

str = input()
N = int(str)
 
str = input().split()
while i < N:
  V.append(int(str[i]))
  i = i+1
  
i=0
str = 0
str = input().split()
while i < N:
  C.append(int(str[i]))
  i = i+1

i=0
while i<N:
  if V[i] > C[i]:
    ans = ans + V[i] - C[i]
    i = i+1
    
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

# 2進数のカウンターを使って全探索する

ans = 0
cnt = 0 # カウンター

def get_value(b):
    """
    バイナリ値bを受け取り、X-Yを計算する
    """
    X = 0
    Y = 0
    for i in range(N):
        if b[i] == "1":
            X += V[i]
            Y += C[i]
    return X - Y

while cnt < 2 ** N:
    b = bin(cnt)[2:]
    ans = max(ans, get_value("0" * (N - len(b)) + b))
    cnt += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
V = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

cand = [int(i) for i in range(N)]
ans = []
for i in range(N):
    hoge = list(itertools.combinations(tuple(cand), i))
    for t in hoge:
        tl = list(t)
        tmp = 0
        for j in tl:
            tmp += (V[j] - C[j])
        ans.append(tmp)
print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
import itertools
n=int(input())
v=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]
ans=[v[i]-c[i] for i in range(n)]+[0]
x=[i for i in range(n)]

for i in range(2,n):
    for z in itertools.combinations(x, i):
        A=0
        for y in z:
            A+=v[y]-c[y]
        ans+=[A]
print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
vl = list(map(int, input().split()))
cl = list(map(int, input().split()))

res = -1

for i in range(2**n):
    x = 0
    y = 0
    for j in range(n):
        if i>>j&1==1:
            x += vl[j]
            y += cl[j]
    res = max(res, x-y)

print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

# ビットで使う使わないパターン表を作る
# Nが桁数、2のN乗がパターン数
max = 0
for i in range(0, 2 ** N):
    ptn = '0' + str(N) + 'b'
    bin_i = list(format(i, ptn))
    work = 0
    for j in range(0, N):
        if bin_i[j] == '1':
            work += V[j] - C[j]
    if max < work:
        max = work

print(max)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
vlist = list(map(int, input().split()))
clist = list(map(int, input().split()))

ans = -100000000000
for num in range(2 ** N):
    value = cost = 0
    for i in range(N):
        if (num >> i) & 1 == 1:
            value += vlist[i]
            cost += clist[i]
    if value - cost > ans:
        ans = value - cost
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = int(input())
V = [int(s) for s in input().split() if s.isdigit()]
C = [int(s) for s in input().split() if s.isdigit()]

maximum = 0
for select in range(1, N+1):
    for comb in combinations(range(N), select):
        value = 0
        for idx in comb:
            value += V[idx] - C[idx]
        if value > maximum:
            maximum = value
print(maximum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

V = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = 0
for i in range(2**N):
    X = 0
    Y = 0
    for j in range(N):
        if ((i >> j) & 1):
            X += V[j]
            Y += C[j]
    ans = max(ans, X-Y)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
v = np.array(list(map(int,input().split()))) 
c = np.array(list(map(int,input().split())))
ans = -(1<<60)
for i in range(2**n):
    temp = (bin(i)[2:]).zfill(n)
    temp = np.array(list(map(int, temp)))
    X = np.dot(temp, v)
    Y = np.dot(temp,c)
    ans = max(ans,X-Y)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
for i in range(1<<N):
    val = 0
    for j in range(N):
        if i >> j & 1:
            val+=V[j]
            val-=C[j]
    ans = max(ans, val)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
import operator

n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

value, cost, ans = [0, 0, 0]
for x in product([0, 1], repeat=n):
    value = sum(map(operator.mul, v, x))
    cost = sum(map(operator.mul, c, x))
    ans = max(ans, value - cost)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
Vn=list(map(int,input().split()))
Cn=list(map(int,input().split()))

best = 0
for i in range(2**N):
    t = 0
    for j in range(N):
        if (i >> j) & 1:
            t += (Vn[j] - Cn[j])
    if t > best:
        best = t
print(best)

Submission status: Time Limit Exceeded

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

import sys
import copy

sys.setrecursionlimit(1000000)

# input = sys.stdin.readline

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

N = int(input())

V = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0

for bit in range(1 << N):
    sum = 0
    for i in range(N):
        if bit & (1 << i):
            sum += V[i]
            sum -= C[i]
    ans = max(ans, sum)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def resale(N: int, V: list, C: list)->int:
    max_diff = 0
    for i in range(1 << N):
        diff = 0
        for j in range(N):
            if i & (1 << j):
                diff += V[j]-C[j]
        max_diff = max(diff, max_diff)
    return max_diff


if __name__ == "__main__":
    N = int(input())
    V = [int(s) for s in input().split()]
    C = [int(s) for s in input().split()]

    ans = resale(N, V, C)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from functools import reduce
import bisect
import random
import fractions
import math
# import statistics
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]  # LIST INT
def LF(): return [float(x) for x in sys.stdin.readline().split()]  # LIST FLOAT
def LS(): return sys.stdin.readline().split()  # LIST STRING
def MI(): return map(int, sys.stdin.readline().split())  # MAP INT
def II(): return int(sys.stdin.readline())  # INPUT INT
def IS(): return input()  # INPUT STRING
def P(x): return print(x)
def C(x): return Counter(x)
def GCD_LIST(numbers):  # Greatest Common Divisor
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):  # Least Common Multiple
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))


n, v, c = II(), LI(), LI()
# n = 20
# v = [random.random()* 100 for i in range(20)]
# c = [random.random()* 100 for i in range(20)]
y = 0
maxi = -INF
start = time.time()
for i in range(2 ** n):
    x = 0
    y = 0
    for j in range(n):
        if i >> j & 1:
            x += v[j]
            y += c[j]
    maxi = max(maxi, x - y)

# print(time.time() - start)
print(maxi)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
V = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
 
max = 0
for bit in range(2**N):
    sum = 0
    count = 0
    for i in range(N):
        if (bit >> i) & 1:
            sum += V[i]-C[i]
        else:
            pass

    if sum > max:
        max = sum
 
print(max)

Submission status: Time Limit Exceeded

Solution code:

def add_one_zero(list):
    return [x+[0] for x in list]+[x+[1] for x in list]

def one_hot(list,max_depth):
    if max_depth==1:
        return add_one_zero(list)
    return one_hot(add_one_zero(list),max_depth-1)

def sum_func(data,index_list):
    sum=0
    for i in range(len(index_list)):
        sum = sum + index_list[i]*data[i]
    return sum

def list_to_XY(one_hot_list,V,C):
    return [sum_func(V,i)-sum_func(C,i) for i in one_hot_list]
    

new_list = [[]]
N = int(input())
V = list( map(int, input().split()) )
C = list(map(int, input().split()))
print(max(list_to_XY(one_hot(new_list,N),V,C)))

Submission status: Time Limit Exceeded

Solution code:
import itertools

if __name__ == '__main__':
  n = input()
  v = input()
  c = input()
  
  v_list = v.split(' ')
  c_list = c.split(' ')
  max_xy = 0
 
  
  for i in range(int(n)):
    for j in itertools.permutations(v_list, r=(i+1)):
      x = 0
      y = 0
      for ji in range(len(j)):
        x += int(j[ji])
        y += int(c_list[v_list.index(j[ji])])

      if (x-y) > max_xy:
        max_xy = x-y
    
  print(max_xy)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
v=list(map(int, input().split()))
c=list(map(int, input().split()))
ans=0

for i in range(2 ** n):
    total = 0
    for j in range(n):  
        if ((i >> j) & 1):  
            total+=v[j]-c[j]        
    ans=max(ans,total)    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    V = list(map(int, input().split()))
    C = list(map(int, input().split()))
    arr = []
    ans = []
    for i in range(N):
        arr.append(V[i]-C[i])
    for j in range(1 << N):
        output = []
        for k in range(N):
            if ((j >> k) & 1) == 1:
                output.append(arr[k])
            ans.append(sum(output))
    if max(ans) < 0:
        print(0)
        return
    print(max(ans))
main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
import numpy as np

N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
V = np.array(V)
C = np.array(C)
arange = np.arange(N)

mx = 0
for M in range(N+1):
	all_perm = itertools.permutations(arange, M)
	for i in all_perm:
		if len(i) == 0:
			continue
		k = np.array(list(i))
		X = V[k].sum()
		Y = C[k].sum()
		if X-Y > mx:
			mx = X-Y
print(mx)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    V = list(map(int, input().split()))
    C = list(map(int, input().split()))
    arr = list()
    ans = list()

    for i in range(N):
        arr.append(V[i]-C[i])
    for j in range(1 << N):
        output = []
        for k in range(N):
            if ((j >> k) & 1) == 1:
                output.append(arr[k])
            ans.append(sum(output))
    if max(ans) > 0:
        print(max(ans))
    else:
        print(0)
main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    V = list(map(int, input().split()))
    C = list(map(int, input().split()))
    arr = list()
    ans = list()
    for i in range(0, N):
        arr.append(V[i]-C[i])
    for j in range(1 << len(arr)):
        output = []
        for k in range(len(arr)):
            if ((j >> k) & 1) == 1:
                output.append(arr[k])
        if len(output) != 0:
            ans.append(sum(output))
    ma_ans = max(ans)
    if ma_ans > 0:
        print(ma_ans)
    else:
        print(0)
main()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import itertools
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))
d = sum(v) - sum(c)
maxd = d if d > 0 else 0
for m in range(1, n):
    a0 = [i for i in list(itertools.combinations(list(range(n)), m))]
    for a1 in a0:
        d = sum([v[j] - c[j] for j in a1])
        if maxd < d:
            maxd = d
print(maxd)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())

test = {}

V = list(map(int,input().split()))
C = list(map(int,input().split()))

for i in range(N):
    test[i] = [V[i],C[i]]


def calc_cost(com,test,i):
    x = 0
    y = 0
    for j in com:
        x += test[j][0]
        y += test[j][1]
    return x - y

ans = 0
for i in range(N):
    c = itertools.combinations(list(range(N)), i+1)
    for j in c:
        ans = max(ans,calc_cost(j,test,i))


print(ans)