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:
import itertools

def combinationListRecursive(data, r):
  if r == 0 or r > len(data):
    return []

  result = []
  _combinationListRecursive(data, r, 0, [], result)
  return result


def _combinationListRecursive(data, r, start, progress, result):
  if r == 0:
    result.append(progress)
    return

  for i in range(start, len(data)):
    _combinationListRecursive(data, r - 1, i + 1, progress + [data[i]], result)



N = int(input())
V = input().split(" ")
C = input().split(" ")
res = []
for i in range(N+1):
    #index = combinationListRecursive(list(range(N)),i)
    index = list(itertools.combinations(list(range(N)),i))
    for ind in index:
        if len(ind) == 0:
            res.append(0)
        else:
            s = 0
            for n in ind:
                s += int(V[n])-int(C[n])
            if s > 0:    
                res.append(s)
            else:
                res.append(0)
print("{}".format(max(res)))

Submission status: Time Limit Exceeded

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

for i in range(n+1):
    for j in combinations(range(n),i):
        x=0
        y=0
        for k in j:
            x+=v[k]
            y+=c[k]
        ans=max(ans,x-y)
print(ans)

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 = 0
maxd = 0
for m in range(1, n + 1):
    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:
def combinationListRecursive(data, r):
  if r == 0 or r > len(data):
    return []

  result = []
  _combinationListRecursive(data, r, 0, [], result)
  return result


def _combinationListRecursive(data, r, start, progress, result):
  if r == 0:
    result.append(progress)
    return

  for i in range(start, len(data)):
    _combinationListRecursive(data, r - 1, i + 1, progress + [data[i]], result)



N = int(input())
V = input().split(" ")
C = input().split(" ")
res = []
for i in range(N+1):
    index = combinationListRecursive(list(range(N)),i)
    for ind in index:
        if len(ind) == 0:
            res.append(0)
        else:
            s = 0
            for n in ind:
                s += int(V[n])-int(C[n])
            if s > 0:    
                res.append(s)
            else:
                res.append(0)
print("{}".format(max(res)))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

x = []
y = []

for i in range(n+1):
    for j in itertools.permutations(v, i):
        x.append(j)
    
    for k in itertools.permutations(c, i):
        y.append(k)

x_sum = []
y_sum = []
for row in x:
    x_sum.append(sum(row))

for row in y:
    y_sum.append(sum(row))

ans = []

for i in range(len(x_sum)):
    ans.append(x_sum[i] - y_sum[i])

print(max(ans))

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 = 0
maxd = 0
for m in range(1, n + 1):
    a0 = [list(i) for i in list(itertools.combinations(list(range(n)), m))]
    for a1 in a0:
        x = sum([v[j] for j in a1])
        y = sum([c[j] for j in a1])
        d = x - y
        if maxd < d:
            maxd = d
print(maxd)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

n = int(input())
value = list(map(int, input().split()))
cost = list(map(int, input().split()))

idx = range(n)
result = [0, sum(value)-sum(cost)]
comb = [com for i in range(1, n) for com in combinations(idx, i)]

for com in comb:
  tmp = 0
  for c in com:
    tmp += value[c]-cost[c]
  result.append(tmp)
    
print(max(result))

Submission status: Time Limit Exceeded

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

Z = [0 for i in range(2**N)]

for i in range(1, 2**N):
    select = []
    temp = i
    for n in reversed(range(1, N+1)):
        if temp - 2**(n-1) >= 0:
            temp = temp - 2**(n-1)
            select.append(n-1)
    Z[i] = sum([V[j] for j in select]) - sum([C[j] for j in select])
print(max(Z))

Submission status: Time Limit Exceeded

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

X = [0 for i in range(2**N)]
Y = [0 for i in range(2**N)]
Z = [0 for i in range(2**N)]

for i in range(1, 2**N):
    select = []
    temp = i
    for n in reversed(range(1, N+1)):
        if temp - 2**(n-1) >= 0:
            temp = temp - 2**(n-1)
            select.append(n-1)
    for j in select:
        X[i] += V[j]
        Y[i] += C[j]
    Z[i] = X[i] - Y[i]
print(max(Z))

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 combinations
List=[]
for i in range(N):
    List.append(i)
ans=[]
for i in range(1,N+1):
    for j in list(combinations(List,i)):
        tmp=0
        for k in j:
            tmp+=V[k]-C[k]
        if tmp<0:
            tmp=0
        ans.append(tmp)    
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()))

Benefit = 0

for b in range(2**N):
	Binary = []
	binary = b
	for n in range(N):
		Binary.append(binary % 2)
		binary = binary //(2)
#	print("Binary = " + str(Binary))
	B = 0
	for n in range(N):
		if Binary[n] == 1:
			B += V[n] - C[n]
	Benefit = max(Benefit, B)
#print("Benefit = " + str(Benefit) )

print(Benefit)

Submission status: Time Limit Exceeded

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

Benefit = []

for b in range(2**N):
	Binary = []
	binary = b
	for n in range(N):
		Binary.append(binary % 2)
		binary = binary //(2)
#	print("Binary = " + str(Binary))
	B = 0
	for n in range(N):
		if Binary[n] == 1:
			B += V[n] - C[n]
	Benefit.append(B)
#print("Benefit = " + str(Benefit) )
print(max(Benefit))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

n = int(input())
value = list(map(int, input().split()))
cost = list(map(int, input().split()))

idx = range(n)
result = [0, sum(value)-sum(cost)]

for i in range(n):
  for com in combinations(idx, i):
    tmp = 0
    for c in com:
      tmp += value[c]-cost[c]
    result.append(tmp)
    
print(max(result))

Submission status: Time Limit Exceeded

Solution code:
import itertools
n=int(input())
v=list(map(int,input().split()))
c=list(map(int,input().split()))
vc=[]
for i in range(n):
  vc.append(v[i]-c[i])
sv=[]
sum=0
for L in range(0, len(v)+1):
    for subset in itertools.combinations(vc, L):
      for i in range(len(subset)):
        sum=sum+int(subset[i])
      sv.append(sum)
      sum=0
print(max(sv))

Submission status: Time Limit Exceeded

Solution code:
import itertools
n=int(input())
v=list(map(int,input().split()))
c=list(map(int,input().split()))
sv=[]
sum=0
sumc=0
for L in range(0, len(v)+1):
    for subset in itertools.combinations(v, L):
      for i in range(len(subset)):
        sum=sum+int(subset[i])
        for j in range(n):
          if int(subset[i])==v[j]:
            sumc=sumc+c[j]
      sv.append(sum-sumc)
      sum=0
      sumc=0
print(max(sv))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

ids = [x for x in range(n)]

store = list()
store.append(0)

for i in range(1, n+1):
    tmpcmb = list(itertools.combinations(ids, i))

    for k, i in enumerate(tmpcmb):
        tmpv = 0
        tmpc = 0
        for j in i:
            tmpv += v[j]
            tmpc += c[j]
        store.append(tmpv - tmpc)

result = max(store)
print(result)

Submission status: Time Limit Exceeded

Solution code:
import itertools,numpy as np
n = int(input())
X = np.array(list(map(int,input().split(' '))))
Y = np.array(list(map(int,input().split(' '))))
Z = X - Y
import itertools,numpy as np
a = list(itertools.product([0,1], repeat=n))
r = 0
print(max([(Z*np.array(i)).sum() for i in a]))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))
maxxy = -10**9
for i in range(2**n):
    s = '0'*n + format(i, 'b')
    sl = list(s)
    #print(s)
    xy = 0
    for j in range(n):
        a = sl.pop(-1)
        if a == '1':
            xy += v[j]
            xy -= c[j]
    if xy > maxxy:
        maxxy = xy
        #print(s)
print(maxxy)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import sys

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

ids = [x for x in range(n)]
# print(ids)
# sys.exit()
cmb = list()
for i in range(1, n+1):
    cmb += list(itertools.combinations(ids, i))
# print(cmb)

store = [0]*len(cmb)
store.append(0)

for k, i in enumerate(cmb):
    tmpv = 0
    tmpc = 0
    for j in i:
        tmpv += v[j]
        tmpc += c[j]
    store[k] = tmpv - tmpc

# print(store)
result = max(store)
print(result)

Submission status: Time Limit Exceeded

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

answer = 0
for i in range(1 << n):
  tmp = 0
  for j in range(n):
    if i & (1 << j):
      tmp += int(v[j]) - int(c[j])
  if answer < tmp:
    answer = tmp

print(answer)

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

for i in range(2**n):
    flugs = bin(i)[2:].zfill(n)
    sum_v = 0
    sum_c = 0
    j = 0
    for flug in str(flugs):
        if flug == '1':
            sum_v += v[j]
            sum_c += c[j]
        j += 1

    if (max_v_minus_c < sum_v - sum_c):
        max_v_minus_c = sum_v - sum_c

print(max_v_minus_c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
size = list(map(int, input().split()))
price = list(map(int, input().split()))

ans = 0

for i in range(2**n-1) :
    tmp_sumS = 0
    tmp_sumP = 0
    tmp_comb = []

    for j in range(n) :
        # シフトして１ビットずつ判断
        is_put = i>>(n-j-1)&1
        tmp_comb.append(is_put)
        tmp_sumS += is_put * size[j]
        tmp_sumP += is_put * price[j]
            
        if tmp_sumS-tmp_sumP > ans:
            ans = tmp_sumS-tmp_sumP

print(ans)

Submission status: Time Limit Exceeded

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

seq1 = 2**N

maximum = 0
for i in range(seq1):
    c_ind = []
    cnt = 0
    X = 0
    Y = 0
    while i>0:
        if i % 2 == 1:
            c_ind.append(cnt)
            X += int(V[cnt])
            Y += int(C[cnt])
        i /= 2
        i = int(i)
        cnt += 1
    if maximum < X-Y:
        maximum = X-Y

print(maximum)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
size = list(map(int, input().split()))
price = list(map(int, input().split()))

max_size = -1
max_price = -1
combination = []
ans = 0

for i in range(2**n-1) :
    tmp_sumS = 0
    tmp_sumP = 0
    tmp_comb = []
    over_flag = False

    for j in range(n) :
        # シフトして１ビットずつ判断
        is_put = i>>(n-j-1)&1
        tmp_comb.append(is_put)
        tmp_sumS += is_put * size[j]
        tmp_sumP += is_put * price[j]
            
        if tmp_sumS-tmp_sumP > ans:
            ans = tmp_sumS-tmp_sumP
    
    # over flag が立ってない かつ 暫定 max price より高いときに更新
    if (not over_flag) and tmp_sumP > max_price :
        max_price = tmp_sumP
        max_size = tmp_sumS
        combination = tmp_comb
    
print(ans)

Submission status: Time Limit Exceeded

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

res = []
for i in range(1 << N):
  X = Y = 0
  for j in range(N):
    if ((i >> j) & 1):
      X += V[j]
      Y += C[j]
  res.append(X-Y)
print(max(res))

Submission status: Time Limit Exceeded

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

cost_max = 0

for i in range(2 ** N):
    x = 0
    y = 0

    for j in range(N):
        if ((i >> j) & 1) == 1:
            x += V[j]
            y += C[j]
    if cost_max < (x - y):
        cost_max = x - y

print(cost_max)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
v_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

max_diff = -10000000
for selection in range(1 << N):
    v_tmp = 0
    c_tmp = 0
    for idx in range(N):
        if (selection >> idx) & 1:
            v_tmp += v_list[idx]
            c_tmp += c_list[idx]
    max_diff = max(max_diff, v_tmp - c_tmp)

print(max_diff)

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

max = 0
pattern = itertools.product(range(2), repeat=N)
for p in pattern:
    sum = 0
    count = 0
    for i in p:
        if i == 1:
            sum += V[count]-C[count]
        else:
            pass
        count +=1
    if sum > max:
        max = sum


print(max)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from functools import reduce
import bisect
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 = II()
v = LI()
c = LI()
y = 0
maxi = -1000000000000
for i in range(2 ** n):
    total = 0
    y =0
    for j in range(n):
        if ((i >> j) & 1):
            total += v[j]
            y += c[j]
    maxi = max(maxi, total-y)

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

ans = -float('inf')
d = len(V)
for b in range(2 ** d):
    tmp = 0
    for j in range(d):
        if ((b >> j) & 1):
            tmp += V[j] - C[j]
    ans = max(ans, tmp)
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):
    value = 0
    cost = 0
    for j in range(n):
        if i >> j & 1:
            value += v[j]
            cost += c[j]
    ans = max(ans, value - cost)

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

def chr(a,l):
#    print(a,l)
    if a == n:
        x = 0
        y = 0
        for i in range(n):
            x += v[i]*l[i]
            y += c[i]*l[i]
        return(x-y)
    else:
        l[a] = 1
        ans1 = chr(a+1,l)
        l[a] = 0
        ans2 = chr(a+1,l)
    return(max(ans1,ans2))
    
l = [0 for i in range(n)]
print(chr(0,l))

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    v = [int(v) for v in input().split()]
    c = [int(c) for c in input().split()]

    max_total = 0
    for i in range(2 ** n):
        total = 0
        for j in range(n):  # このループが一番のポイント
            if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
                total += v[j]
                total -= c[j]
        if total > max_total:
            max_total = total
    print(max_total)

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()))
a=[]
for i in range(1<<N):
    tmp=0
    for j in range(N):
        if ((i >> j) & 1) == 1:
          tmp+=V[j]-C[j]
    a.append(tmp)
print(max(a))

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

maxv = 0
for i in range(1, N+1):
    for t in list(combinations(list(range(N)), i)):
        X = sum(V[k] for k in t)
        Y = sum(C[k] for k in t)
        maxv = max(maxv, X-Y)
print(maxv)

Submission status: Time Limit Exceeded

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

take = [0 for _ in range(N)]
ans = 0

def up(i):
    if i == N:
        return False
    take[i] += 1
    if take[i] == 2:
        take[i] = 0
        return up(i + 1)
    return True

while True:
    sum = 0
    for i in range(N):
        if take[i] == 1:
            sum += V[i] - C[i]
    if sum > ans:
        ans = sum
    if not up(0):
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n = ni()
v = nl()
c = nl()
ans = 0
for i in range(2 ** n):
    lis = list(bin(i)[2:].zfill(n))
    tmp = 0
    for l in range(len(lis)):
        tmp += int(lis[l]) * (v[l] - c[l])
    ans = max(ans, tmp)
print(ans)

Submission status: Time Limit Exceeded

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

maxV = 0
for i in range(2**N):
    bit = i
    X = Y = 0
    for j in range(N):
        mod = bit%2
        bit = bit//2
        if(mod==1):
            X += V[j]
            Y += C[j]
    maxV = max(maxV, X-Y)

print(maxV)

Submission status: Time Limit Exceeded

Solution code:
import sys
# import bisect
# import math
# import itertools
import numpy as np
# import collections

"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e, p = range, enumerate, print
    ip = IP()
    id = Idea()
    mod = 10 ** 9 + 7

    """この下から書いてね"""
    n = ip.I()
    v = ip.IL()
    c = ip.IL()
    ans = 0
    for i in r(2 ** n):
        x = []
        y = []
        for j in r(n):
            if (i >> j) & 1:
                x.append(v[j])
                y.append(c[j])
        x = np.array(x)
        y = np.array(y)
        ans = max(sum(x) - sum(y), ans)
    p(ans)


main()

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 = []

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

print(max(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()))
ans = 0
for i in range(n + 1):
    for j in itertools.combinations(range(n), i):
        x = 0
        y = 0
        for z in j:
            x += v[z]
            y += c[z]
        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()))

import itertools

#n桁のm値のbitを生成
def bit(n, m):
    bit_list = list(itertools.product([i for i in range(m)], repeat=n))
    return bit_list

bts = bit(N, 2)

res = 0
for b in bts:
    tmp = 0
    for i in range(N):
        if b[i] == 0:
            tmp += V[i] - C[i]
            
    if tmp > res:
        res = tmp
        
print(res)

Submission status: Time Limit Exceeded

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

ans = float('-inf')
for i in range(2 ** N):
  t = 0
  for j in range(N):
    if i & (1 << j):
      t += V[j]
      t -= C[j]
  ans = ans if ans > t else t
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):
	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:
N = int(input())

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

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

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

ans = -10**18
for p in product([0, 1], repeat=N):
    res = 0
    for i, e in enumerate(p):
        if e:
            res += V[i] - C[i]
    ans = max(ans, res)
print(ans)

Submission status: Accepted

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

L = []
for i in range(n):
    if V[i]-C[i] >= 0:
        L.append(V[i]-C[i])

print(sum(L))

Submission status: Accepted

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

for i in range(n):
    if v[i] > c[i]:
        cnt += v[i] -c[i]
        
print(cnt)

Submission status: Accepted

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

P=V-C

ans = 0
for i in P:
	if i>=0:
		ans += i

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
for i in range(n):
  if v[i]-c[i] > 0:
    ans += v[i]-c[i]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

v = [int(s) for s in input().split()]
c = [int(s) for s in input().split()]

sum_ = 0
for i in range(n):
    if v[i] - c[i] > 0:
        sum_ += v[i] - c[i]
print(sum_)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
V = list(map(int,input().split()))
C = list(map(int,input().split()))
diff_VC = list(i-j for i,j in zip(V,C))
c=[]
for i in range(N):
  c += [sum(comb) for comb in itertools.combinations(diff_VC,i+1)]
print(max(max(c),0))

Submission status: Accepted

Solution code:
n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
for i in range(n):
    if v[i] - c[i] > 0:
        ans += v[i] - c[i]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
 
diff = [V[i] - C[i] for i in range(N)]
diff.sort(reverse=True)
 
i, ans = 0,0
for d in diff:
    if d <= 0:
        break
    ans += d
print(ans)

Submission status: Accepted

Solution code:
input()
print(sum((v-c for v,c in zip(map(int,input().split()),map(int,input().split())) if v-c>0)))

Submission status: Accepted

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

ans = 0
diff = [0 for i in range(N)]
for i in range(N):
  if V[i] - C[i] > 0:
    ans += V[i] - C[i]
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(N):
  if V[i] > C[i]:
    ans += V[i] - C[i]
print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    V = [int(x) for x in input().split()]
    C = [int(x) for x in input().split()]
    ans = 0
    
    for v, c in zip(V, C):
        if v - c > 0:
            ans += v - c
        else:
            ans += 0
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))
cnt = 0
for i in range(n):
    if v[i] > c[i]:
        cnt += v[i] - c[i]
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
for i in range(len(v)):
    if v[i]-c[i]>=0:
        ans = ans + v[i] - c[i]
        
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
v=list(map(int, input().split()))
c=list(map(int, input().split()))
score=0
for i in range(n):
  if v[i]-c[i]>0:
    score+=v[i]-c[i]
print(score)

Submission status: Accepted

Solution code:
n = int(input())
list_v = [int(i) for i in input().split()]
list_c = [int(j) for j in input().split()]
ans = 0
for i in range(0, n):
    if list_v[i] - list_c[i] > 0:
        ans += (list_v[i] - list_c[i])
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
 
ans = 0
for i in range(N):
  tmp = V[i] - C[i]
  if tmp > 0: ans += tmp

print(ans)

Submission status: Accepted

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

D = [V[i] - C[i] for i in range(N)]
ans = 0
for i in range(N):
  if D[i] > 0: ans += D[i]

print(ans)

Submission status: Accepted

Solution code:
import math


def main():
    n = int(input())
    # a, b, t = map(int, input().split())
    # h = list(map(int, input().split()))
    # s = input()
    # h = [int(input()) for _ in rane(n)]

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

    sub = [v[i]-c[i] for i in range(n)]

    ans = 0
    for num in sub:
        if num >0:
            ans +=num

    print(ans)






if __name__ == '__main__':
    main()

Submission status: Accepted

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

ANS = 0

for i in range(N):
    if V[i] > C[i]:
        ANS = ANS + (V[i] - C[i])
        
print(ANS)

Submission status: Accepted

Solution code:
n = int(input())
v = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
l = [0]*n

for i in range(n):
    l[i] = v[i]-c[i]
    if(l[i] < 0):
        l[i]=0
    
print(sum(l))