Qiita Teams that are logged in
You are not logged in to any team

Community
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@RubyLrving

# A - Repeat ACL, B - Balance, C - Exam and Wizard

2021/2/12
くじかつ精進

## A - Repeat ACL

O(1)

python
``````N = int(input())

S = ""
for i in range(0, N):
S += "ACL"

print(S)
``````

## B - Balance

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

## C - Exam and Wizard

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)
``````
0
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
1. We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
2. you can read useful information later efficiently
By "stocking" the articles you like, you can search right away
エンジニア。 c/c++、pythonをメインで記述しています。