AtCoder Beginner Contest 137
はい。
https://atcoder.jp/contests/abc137
ooox-- ダメです。
A - +-x
PyPy3
a,b=map(int,input().split()) print(max(a+b,a-b,a*b))
3件を全部計算してmaxで取り出します。
B - One Clue
PyPy3
k,x=map(int,input().split()) if k==1: ans=[x] else: ans=list(range(x-k+1,x+k)) print(*ans)
xを中心に左右にk-1個可能性ありです。リストを作成して出力してます。
C - Green Bin
PyPy3
n=int(input()) d={} for i in range(n): w=list(input()) w.sort() s="".join(w) if s in d: d[s]+=1 else: d[s]=1 ans=0 for i in d: ans+=d[i]*(d[i]-1)//2 print(ans)
それぞれの文字列は受取時に文字ごとばらばらにしてソートしてから結合しなおしておいて、受取後に同じ文字列を探して数えます。
D - Summer Vacation
PyPy3
#from https://atcoder.jp/contests/abc137/submissions/6808061 import heapq import sys input=sys.stdin.readline def sol(): n,m=map(int,input().split()) d=[] for i in range(n): a,b=map(int,input().split()) if a<=m: d.append((a,b)) d.sort(reverse=True) q=[] ans=0 for i in range(1,m+1): while d and d[-1][0]<=i: a,b=d.pop() heapq.heappush(q,-b) if q: ans += -heapq.heappop(q) print(ans) if __name__=="__main__": sol()
はい。
アルバイト情報の入力受取はとりあえずそのまま (a,b) でリストに追加し続けます。
受取後にsort(reverse=True)します。
今日からアルバイトをするので for i in range(1,m+1) します。
アルバイト候補で受取が間に合う案件はheappushで、報酬の値を反転させて追加し続けます。
候補を調べた後でi日目に受取が間に合うもので報酬が最大のものを選択します。heappopで取り出します。
選択したお仕事の報酬を加算します。
アルバイト案件があるか、m日までは繰り返します。
解になります。
という感じです。多分。。