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: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import itertools

# input
l = list(map(int, input().split()))
N = l[0]

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

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

best_result = 0

# 総選択数 n
for n in range(N):
    v_list = list(itertools.combinations(V,n));
    c_list = list(itertools.combinations(C,n));
    for v, c in zip(v_list, c_list):
        X = sum(v)
        Y = sum(c)

        result = X - Y

        # Renew
        if best_result < result:
            best_result = result

print(best_result)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import itertools

# input
l = list(map(int, input().split()))
N = l[0]

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

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

best_result = 0

# 総選択数 n
for n in range(N):
    print("n", n)

    v_list = list(itertools.combinations(V,n));
    c_list = list(itertools.combinations(C,n));
    for v, c in zip(v_list, c_list):
        X = sum(v)
        Y = sum(c)

        result = X - Y

        # Renew
        if best_result < result:
            best_result = result

print(best_result)

Submission status: Wrong Answer

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

X = 0
Y = 0

for i in range(N):
    if V[i] > C[i]:
        X = V[i]
        Y = V[i]
        X += X
        Y += Y

if (X-Y) > 0:
    print(X-Y)

Submission status: Wrong Answer

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

X = 0
Y = 0

for i in range(N):
    if V[i] < C[i]:
        X = V[i]
        Y = V[i]
        X += X 
        Y += Y

if (X-Y) > 0:
    print(X-Y)

Submission status: Wrong Answer

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

print(result)

Submission status: Wrong Answer

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 = sum(v) - sum(c)
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: Wrong Answer

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

Y=0
for x in [0,N-1]:
    Y+=max(0,V[x]-C[x])

print(Y)

Submission status: Wrong Answer

Solution code:
n= int(input())

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

for i in range(n):
  r.append(v[i]-c[i]) 

r.append(0)
r.sort(reverse=True)
print(r)

ret= sum([j for j in r if j>=0])
print(ret)

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
result = 0
for i in range(N):
    if V[i] is not V[0] and C[i] is not C[0]:
        x = V[0]+V[i]
        y = C[0]+C[i]
        if x-y > result:
            result = x-y

print(result)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np

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

X = 0
X_ = []
Y = 0
Y_ = []
Z = []

for i in range(N):
    for value in itertools.combinations(V, i+1):
        X = sum(value)
        X_.append(X)

for j in range(N):
    for cost in itertools.combinations(C, j+1):
        Y = sum(cost)
        Y_.append(Y)

print(max(np.array(X_)-np.array(Y_)))

Submission status: Wrong Answer

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))]
    print(a0)
    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: Wrong Answer

Solution code:
from functools import reduce
import numpy as np
input()
a = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))
print(reduce(lambda x,y: max(0,x)+max(0,y), list(a-b)))

Submission status: Wrong Answer

Solution code:
from functools import reduce
import numpy as np
input()
a = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))
print(reduce(lambda x,y: x+max(0,y), list(a-b)))

Submission status: Wrong Answer

Solution code:
from functools import reduce
import numpy as np
a = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))
print(reduce(lambda x,y: max(0,x)+max(0,y), list(a-b)))

Submission status: Wrong Answer

Solution code:
N = int(input())
vLst = list(map(int, input().split()))
cLst = list(map(int, input().split()))

ansMax = 0
if N > 1:
    for i in range(N - 1):
        for j in range(i + 1, N):
            X = vLst[i]
            Y = cLst[i]
            for k in range(j, N):
                X += vLst[k]
                Y += cLst[k]
            ansMax = max(ansMax, X - Y)
else:
    ansMax = max(ansMax, vLst[0] - cLst[0])
print(ansMax)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

v = np.array(v)
c= np.array(c)
hikizan = v-c

x = np.zeros((3,n))
x[1] = v
x[2] = c
x[0] = hikizan

a = x[: , x[0,:].argsort()]

kotae = 0

for i in range(0,n):
    if a[0,i] > 0:
        kotae += a[0,i]
        
print(kotae)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = input().split()
c = input().split()
v = list(map(int, v))
c = list(map(int, c))
diff = list()
for i in range(n):
    diff.append(v[i] - c[i])

diff.sort()
diff.reverse()
if len(diff) >= 2:
    print(diff[0] + diff[1])

elif diff[0] <= 0:
    print(0)

else:
    print(diff[0])

Submission status: Wrong Answer

Solution code:
n= int(input())

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

for i in range(n):
  r.append(v[i]-c[i]) 

r.sort(reverse=True)
r.append(0)
ret= r[0]+r[1]

if ret>0:
  print(ret)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n= int(input())

v= list(map(int, input().split())) 
v.append(0)
c= list(map(int, input().split()))
c.append(0)
r=[]

for i in range(n+1):
  r.append(v[i]-c[i]) 

r.sort(reverse=True)

ret= r[0]+r[1]

if ret>0:
  print(ret)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = input().split()
c = input().split()
v = list(map(int, v))
c = list(map(int, c))
diff = list()
for i in range(n):
    diff.append(v[i]- c[i])

diff.sort()
diff.reverse()
if len(diff) >= 2:
    print(diff[0] + diff[1])

elif diff[0] <= 0:
    print(0)

else:
    print(diff[0])

Submission status: Wrong Answer

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

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

profits = []
z = 0

for i in range(n):
    profits.append(v[i] - c[i])
profits.sort()

#print(profits)

for i in profits:
    p = profits.pop()
    if p < 0:
        print(z)
        exit()
    else:
        z += p
print(z)

Submission status: Wrong Answer

Solution code:
#0WA n==1 mod saikikilimit exit
import sys
input = sys.stdin.readline

n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = []
for i in range(n):
    ans.append(v[i]-c[i])
ans.sort()
print(max(0,sum(ans)-ans[0]))

Submission status: Wrong Answer

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

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

profits = []
z = 0

for i in range(n):
    profits.append(v[i] - c[i])
profits.sort()

print(profits)

for i in profits:
    p = profits.pop()
    if p < 0:
        print(z)
        exit()
    else:
        z += p
print(z)

Submission status: Wrong Answer

Solution code:
#0WA n==1 mod saikikilimit exit
import sys
input = sys.stdin.readline

n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = []
for i in range(n):
    ans.append(v[i]-c[i])
ans.sort()
print(sum(ans)-ans[0])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

profits = []
z = 0

for i in range(n):
    profits.append(v[i] - c[i])
profits.sort()

#print(profits)

for i in profits:
    p = profits.pop()
    if p <= 0:
        print(z)
        exit()
    else:
        z += p
print(z)

Submission status: Wrong Answer

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

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

profits = []
z = 0

for i in range(n):
    profits.append(v[i] - c[i])
profits.sort()

print(profits)

for i in profits:
    p = profits.pop()
    if p <= 0:
        print(z)
        exit()
    else:
        z += p
print(z)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
if n==1:
  ans = max(ans, (v[0]-c[0]))

else:
  for i in range(n):
    for j in range(n):    
      if i!=j:
        x = v[i]+v[j]
        y = c[i]+c[j]
        tmp = x - y
        ans = max(ans, tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
V=list(map(int, input().split())) 
C=list(map(int, input().split()))
A=[]
for i in range(N):
  A.append(V[i]-C[i])

A.sort()
A.reverse()
if A[0]>0:
  print(A[0]+A[1])
else:
  print(0)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

N = input()

V = input().split()
v = np.array([ int(x) for x in V])

C = input().split()
c = np.array([ int(x) for x in C])

delt = v - c
print(delt)
print(delt[delt>0].sum())

Submission status: Wrong Answer

Solution code:
N = int(input())
vLst = list(map(int, input().split()))
cLst = list(map(int, input().split()))

ansMax = 0
if N > 1:
    for i in range(N - 1):
        for j in range(i, N - 1):
            X = vLst[i] + vLst[j + 1]
            Y = cLst[i] + cLst[j + 1]
            ansMax = max(ansMax, X - Y)
else:
    ansMax = max(ansMax, vLst[0] - cLst[0])
print(ansMax)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
ans=0
for i in range(n):
    c.append(a[i]-b[i])

print(c)
for i in c:
    if i>=0:
        ans+=i
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
vLst = list(map(int, input().split()))
cLst = list(map(int, input().split()))

ansMax = 0
if N > 1:
    for i in range(N - 1):
        for j in range(i, N - 1):
            X = vLst[i] + vLst[j + 1]
            Y = cLst[i] + cLst[j + 1]
            ansMax = max(ansMax, X - Y)
print(ansMax)

Submission status: Wrong Answer

Solution code:
t = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))
a = sum(v)
b = sum(c)
mxx = abs(a-b)
for i in range(t):
    temp = abs(a-b)
    a1 = a - v[i]
    b1 = b - c[i]
    if(abs(a1-b1)>temp):
        a = a1
        b = b1
        mxx = abs(a-b)
        
print(mxx)

Submission status: Wrong Answer

Solution code:
N=int(input())
V=[]
C=[]
dif=[]
sum=0
V=list(input().split())
C=list(input().split())
for i in range(N):
    dif.append(int(V[i])-int(C[i]))
print(dif)
for i in range(N):
    if dif[i]>=0:
        sum+=dif[i]
print(sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().strip().split(' ')))
c = list(map(int, input().strip().split(' ')))
l = [0] * n
for i in range(n):
  l[i]=v[i]-c[i]
l.sort(reverse=True)
s = 0
for i in range(n):
  if s < sum(l[0:i]):
    s = sum(l[0:i])
print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())
vLst = list(map(int, input().split()))
cLst = list(map(int, input().split()))

ansMax = 0
if N > 1:
    for i in range(N - 1):
        for j in range(i + 1, N):
            X = vLst[i] + vLst[j]
            Y = cLst[i] + cLst[j]
            ansMax = max(ansMax, X - Y)
print(ansMax)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

max_diff = 0

for i in range(1<<n):
    ume = "0"+str(n)
    combi = bin(i)[2:]
    value = 0
    cost = 0
    for j,ch in enumerate(combi):
        if ch == "1":
            value += v_list[j]
            cost += c_list[j]
    if max_diff  < value-cost:
        max_diff = value-cost
print(max_diff)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().strip().split(' ')))
c = list(map(int, input().strip().split(' ')))
l = [0] * n
for i in range(n):
  l[i]=v[i]-c[i]
l.sort(reverse=True)
s = 0
for i in range(n):
  if s < sum(l[0:i-1]):
    s = sum(l[0:i-1])
print(s)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
c=list(map(int,input().split()))
s=sorted([a-b for a,b in zip(v,c)])[::-1]
d=[sum(s[:i])for i in range(len(s))]
print(max(max(d),0))

Submission status: Wrong Answer

Solution code:
n = int(input())
value = list(map(int, input().split()))
cost = list(map(int, input().split()))
ret = 0
for state in range((1 << n) - 1):
    values = costs = 0
    for shift in range(n):
        if (state >> shift) & 1 == 1:
            values += value[shift]
            costs += cost[shift]
    ret = max(ret, values - costs)
print(ret)

Submission status: Wrong Answer

Solution code:
n = input()
V = input().split(" ")
C = input().split(" ")

n = int(n)
V_tmp = []
for v in V:
    V_tmp.append(int(v))
V = V_tmp
C_tmp = []
for c in C:
    C_tmp.append(int(v))
C = C_tmp
SA = []
for i in range(n):
    SA.append(V[i]-C[i])
max_ = 0
for i in range(n):
    if SA[i] >= 0:
        max_ += SA[i]
print(max_)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
c=list(map(int,input().split()))
s=sorted([a-b for a,b in zip(v,c)])[::-1]
d=[sum(s[:i])for i in range(len(s))]
print(max(d))

Submission status: Wrong Answer

Solution code:
n = input()
V = input().split(" ")
C = input().split(" ")

n = int(n)
V_tmp = []
for v in V:
    V_tmp.append(int(v))
V = V_tmp
C_tmp = []
for c in C:
    C_tmp.append(int(v))
C = C_tmp
SA = []
for i in range(n):
    SA.append(C[i]-V[i])
max_ = 0
for i in range(n):
    if SA[i] >= 0:
        max_ += SA[i]
print(max_)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().strip().split(' ')))
c = list(map(int, input().strip().split(' ')))
l = [0] * n
for i in range(n):
  l[i]=v[i]-c[i]
l.sort(reverse=True)
print(sum(l[0:n-1]))

Submission status: Wrong Answer

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

ans = -float('inf')
for b in range(1 << N):
    tmp = 0
    for k, c in enumerate(format(b, '0' + str(len(str(b))) + 'b')):
        if c == '1':
            tmp += V[k] - C[k]
    ans = max(ans, tmp)
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
V.sort()
C.sort()
V_C = []
for i in range(N):
    if V[i] > C[i]:
        V_C.append(V[i]-C[i])
print(sum(V_C))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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(1, n+1):
    a = itertools.combinations(range(n), i)
    for j in a:
        x, y = 0, 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:
import itertools

N = int(input())
V = list(map(int,input().split()))
C = list(map(int,input().split()))
temp = itertools.product([0, 1], repeat=N)
ans = 0
for T in temp:
    an = 0
    for i, e in enumerate(T):
        if e == 1:
            an += V[i] - C[i]
    ans = max(ans,an)
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 = -float("inf")
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]
  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()))

x=0
for i in range(2**n):
    cost=0
    value=0
    for j in range(n):
        if i>>j&1:
            cost+=c[j]
            value+=v[j]
    else:
        if value-cost>x:
            x=value-cost
            


print(x)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))
xy = []
for i in range(1,n+1):
    for h in itertools.combinations(range(0,n),i):
        x = 0
        y = 0
        for j in h:
            x += v[j]
            y += c[j]
        xy.append(x-y)
if max(xy) < 0:
    print(0)
else:
    print(max(xy))

Submission status: Time Limit Exceeded

Solution code:
#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

n=int(input())
v=input_array()
c=input_array()

ans=-10000
for i in range(2**n):
	X=0
	Y=0
	tmp=[]
	for j in range(n):
		tmp.append((i>>j)&1)
	for ct in range(n):
		if tmp[ct]==1:
			X+=v[ct]
			Y+=c[ct]
	if (X-Y)>ans:
		ans=X-Y
print(ans)

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()]
B = []
for i in range(N):
    B.append(V[i] - C[i])
#print(B)

max_profit = 0
for i in range(2**N):
    
    profit = 0
    for j in range(N):
        if i & (1 << j):
            profit += B[j]
    
    max_profit = max(max_profit, profit)

print(max_profit)

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):
  k = 0
  m = 0
  for j in range(n):
    if (i >> j) & 1:
      k += v[j]
      m += c[j]
  ans = max(ans, k - m)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    v = list(map(int, input().split()))
    c = list(map(int, input().split()))
    ans = 0
    
    for i in range(2**n):
        value, cost = 0, 0
        for j in range(n):
            if i >> j & 1:
                value += v[j]
                cost += c[j]
        ans = max(ans, value - cost)
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**7)
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(2**n):
    vsum = 0
    csum = 0
    for i in range(n):
        if (bit & (1 << i)):
            vsum += v[i]
            csum += c[i]
    ans = max(vsum - csum, ans)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N = ii()
V = li()
C = li()

B = 2**N

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n=int(input())
lis=[list(map(int,input().split())) for _ in range(2)]
ans=0

for li in itertools.product([0,1], repeat=n):
  v=0
  for id,l in enumerate(li):
    if l:
      v += lis[0][id] - lis[1][id]
      
  if v > ans:
    ans=v
    
print(ans)

Submission status: Time Limit Exceeded

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

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

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

ans_list = []
for i in range(len(value_result)):
    ans = sum(value_result[i]) - sum(cost_result[i])
    ans_list.append(ans)

if max(ans_list) > 0:
    print(max(ans_list))
else:
    print(0)

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())
l = [(i, j) for i,j in zip(V, C)]

ans = -10**12
for i in p(range(2), repeat=N):
    X, Y = 0, 0
    for j, k in enumerate(i):
        if k==1:
            X += V[j]
            Y += C[j]
    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()))

op_cnt = N
Lis = list()
for i in range(2 ** op_cnt):
    op = [0] * op_cnt  
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - 1 - j] = 1
    lis = list()
    for i,j in enumerate(op):
        lis.append(V[i] * j - C[i] * j)
    Lis.append(sum(lis))

print(max(Lis))

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()]
m = 0
for p in range(2**N):
  value = 0
  for i in range(N):
    if ((p>>i) & 1):
      value = value + V[i] - C[i]
  if value > m:
    m = value
print(m)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

l = [True, False]
max_diff_v_c = 0
for flags in itertools.product(l, repeat=n):
    # print(' '.join(map(str, flags)))
    
    sum_v = 0
    sum_c = 0
    for i in range(len(flags)):
        if flags[i]:
            sum_v += v[i]
            sum_c += c[i]

    diff_v_c = sum_v - sum_c

    if max_diff_v_c < diff_v_c:
        max_diff_v_c = diff_v_c
        
print(max_diff_v_c)

Submission status: Time Limit Exceeded

Solution code:
import itertools


def bit_patterns(n):
    return list(itertools.product(range(2), repeat=n))


def actual(n, V, C):
    diff_list = []

    for bit_pattern in bit_patterns(n):
        values = sum([bit * value for bit, value in zip(bit_pattern, V)])
        costs = sum([bit * cost for bit, cost in zip(bit_pattern, C)])

        diff_list.append(values - costs)

    return max(diff_list)

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

print(actual(n, V, C))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

n = [i for i in range(N)]
ind = []
for i in range(1, N + 1):
    ind += list(itertools.combinations(n, i))

# print(ind)

M = len(ind)
ans = 0
for val in ind:
    X = 0
    Y = 0
    for v in val:
        X += V[v]
        Y += C[v]
        c = X - Y
    ans = max(ans, c)
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(2**n):
    x=0
    y=0
    for j in range(n):
        if (i>>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 bit in range(1 << n):
    tmp = 0
    for i in range(n):
        if bit >> i & 1:
            tmp += v[i] - c[i]
    ans = max(ans, tmp)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import numpy as np


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

    V = np.array(V)
    C = np.array(C)

    ans = 0
    for j in range(1, N + 1):
        combination = itertools.combinations(list(range(N)), j)

        for i in list(combination):
            i = list(i)
            tmp = np.sum(V[i]) - np.sum(C[i])
            ans = max(ans, tmp)

    print(ans)


resolve()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
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)

ans = 0
for i in itertools.product([0, 1], repeat=n):
    ans = max(np.sum(np.array(i)*(v-c)), ans)

print(ans)

Submission status: Time Limit Exceeded

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

xy = []

for i in range(2 ** N):
  value = 0
  cost = 0
  for j in range(N):
    if ((i >> j) & 1):
      value += V[j]
      cost += C[j]
  
  xy.append(value - cost)
  
print(max(xy))

Submission status: Time Limit Exceeded

Solution code:
# 初期入力
import numpy as np
import sys
input = sys.stdin.readline
N = int(input())
V = np.array(list(map(int, input().split())))
C = np.array(list(map(int, input().split())))

#どの宝石を選ぶか全探索
v_c_sum=[]
from itertools import combinations
for i in range(N+1):
    for t in combinations(range(N), i):
        v =np.sum(V[list(t)])
        c =np.sum(C[list(t)])
        v_c_sum.append(v-c)
print(max(v_c_sum))

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    N = int(input())
    V = [int(i) for i in input().split()]
    C = [int(i) for i in input().split()]
    maxA = 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]
        maxA = max(maxA, X - Y)
    print(maxA)


resolve()

Submission status: Time Limit Exceeded

Solution code:
# 初期入力
import sys
input = sys.stdin.readline
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

#どの宝石を選ぶか全探索
v_c_sum=[]
from itertools import combinations
for i in range(N+1):
    for t in combinations(range(N), i):
        v=0
        c=0
        for j in t:
            v +=V[j]
            c +=C[j]
        v_c_sum.append(v-c)
print(max(v_c_sum))
#print(v_c_sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))
ans=-10*18
for i in range(1<<n):
    mask=[(i>>j)&1 for j in range(n)]
    X=0
    Y=0
    for k, m in enumerate(mask):
        if m==1:
            X+=v[k]
            Y+=c[k]
    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
def nibutan(d):
    if len(d)==n:
        global ans
        x = y = 0
        for i in range(n):
            if d[i]==1:
                x += v[i]
                y += c[i]
        ans = max(ans,x-y)
    else:
        nibutan(d+[1])
        nibutan(d+[0])
nibutan([])
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(2**n):
    list_v = []
    list_c = []
    for j in range(n):
        if (i >> j) &1 ==1:
            list_v.append(v[j])
            list_c.append(c[j])
    if sum(list_v) - sum(list_c) >= result:
        result = sum(list_v) - sum(list_c)

print(result)

Submission status: Time Limit Exceeded

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

for i in range(2**n):
    list_v = []
    list_c = []
    for j in range(n):
        if (i >> j) &1 ==1:
            list_v.append(v[j])
            list_c.append(c[j])
    result.append(sum(list_v)-sum(list_c))

print(max(result))

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):
    b = [0] * n
    for j in range(n):
        if i >> j & 1:
            b[j] = 1
    X = sum([v for i, v in enumerate(V) if b[i] == 1])
    Y = sum([c for i, c in enumerate(C) if b[i] == 1])
    ans = max(ans, X - Y)
print(ans)