2021/2/12
くじかつ精進
O(1)
python
N = int(input())
S = ""
for i in range(0, N):
S += "ACL"
print(S)
O(N)
python
import math
import itertools
N = int(input())
W = list(map(int, input().split()))
S1 = 0
S2 = sum(W)
res = 10000
for i in range(0, N):
S1 += W[i]
S2 -= W[i]
res = min(res, abs(S2-S1))
print(res)
O(N)
python
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
total = 0
total_BtoA = 0
total_AtoB = 0
total_AtoB_0 = 0
C = []
for i in range(0, N):
if B[i] > A[i]:
total_BtoA+=1
total += B[i] - A[i]
elif B[i] < A[i]:
C.append(A[i] - B[i])
else:
total_AtoB_0 += 1
C.sort(reverse=True)
for i in range(0, len(C)):
if total >=0:
total -= C[i]
total_AtoB+=1
if total>0:
print(-1)
elif (len(C) + total_AtoB_0 == N):
print(0)
else:
print(total_AtoB + total_BtoA)