1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

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

Posted at

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)
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?