0
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?

[ABC431] ABC 431(Atcoder Beginner Contest)のA~C(A,B,C)問題をPythonで解説(復習)

Posted at

[ABC431] ABC 431(Atcoder Beginner Contest)のA~C(A,B,C)問題をPythonで解説(復習)

合計回答時間: 45分

A問題

自分の回答

かかった時間:2分

H,B = map(int,input().split())

if H <= B:
    print(0)
else:
    print(H-B)

B問題

自分の回答

かかった時間:8分

# はじめロボットの重さは31
# 同時に取り付けられる部品が4つある
# 種類3の重さは65
# 4個のクエリを処理せよ
# ロボットに種類3の部品がついていない場合は取り付け、ついている場合は取り外す。
# その後にロボットの重さを出力する

X = int(input())
N = int(input())
W = list(map(int,input().split()))
Q = int(input())

have = []
ans = X
for i in range(Q):
    P = int(input())
    if P in have:
        have.remove(P)
        ans -= W[P-1]
        print(ans)
    else:
        have.append(P)
        ans += W[P-1]
        print(ans)

C問題

自分の回答

かかった時間:35分

# 高橋くん頭パーツ6個、体パーツ6個持ってる
# 2番目の頭パーツは7,2番目の体パーツは8
# 倒れないロボットを合計3体作りたい
# 二重for文回した時点でTLE

# H<Bとなるような組み合わせをK個作りたい
# Hの3つ目が2,つまり、Bに2以上の値が3以上あればYes

N,M,K = map(int,input().split())
H = list(map(int,input().split()))
B = list(map(int,input().split()))

sh = sorted(H)
sb = sorted(B)
ans_h = sh[:K]
ans_b = sb[M-K:]

for i in range(K):
    if ans_h[i] > ans_b[i]:
        print('No')
        exit()
print('Yes')

次に向けてやること

・C問題に慣れる、二重for文を改善する問題など

感想

A,B問題は安定して解けるようになってきた、C問題の二重for文改善と基本的なアルゴリズムの問題といていこう

補足

関係するリンク(参考文献など)

今回のコンテスト

回答の正当性は保証できません。ベストエフォート方式です。

0
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
0
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?