結果
問題 | No.1708 Quality of Contest |
ユーザー |
![]() |
提出日時 | 2021-10-19 23:53:44 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,035 ms / 2,000 ms |
コード長 | 2,544 bytes |
コンパイル時間 | 277 ms |
コンパイル使用メモリ | 82,100 KB |
実行使用メモリ | 149,620 KB |
最終ジャッジ日時 | 2024-09-20 06:28:44 |
合計ジャッジ時間 | 17,520 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
import sys#input = sys.stdin.readlineinput = sys.stdin.buffer.readlinefrom heapq import heapify, heappop, heappushdef main():N,M,X = map(int,input().split())A = []; B = []not_used = []; used = []for _ in range(N):a,b = map(int,input().split())A.append(a)B.append(b)heappush(not_used,(-a,b)) #値、組K = int(input())C = list(map(int,input().split()))dic = {}for c in C:if c in dic:dic[c] += 1else:dic[c] = 1L = []used_group = set([])score = 0ans = 0for i in range(N):if used:a,b = heappop(used)val_used_group = (-a,b)else:val_used_group = (0,0) #dummyval_not_group = (0,0) #dummywhile not_used:a,b = heappop(not_used)a *= -1 #正に値に直す#print(a,b)#print("VAL",val_used_group)if b not in used_group:val_not_group = (a,b)breakelse:if val_used_group[0] > a: #既に出した値が同じ組中で最高heappush(used,(-a,b))else:temp = (a,b)val_used_group, temp = temp, val_used_groupa,b = tempheappush(used,(-a,b))#print(val_used_group,val_not_group)if val_used_group == (0,0):L.append(val_not_group)used_group.add(val_not_group[1])score += val_not_group[0] + Xelif val_not_group == (0,0):L.append(val_used_group)used_group.add(val_used_group[1])score += val_used_group[0]else:score_used = score + val_used_group[0]socre_not = score + val_not_group[0] + X #1組増えるのでif score_used > socre_not: #使用済みのグループを使う。score = score_usedL.append(val_used_group)used_group.add(val_used_group[1])heappush(not_used,(-val_not_group[0],val_not_group[1]))else:score = socre_notL.append(val_not_group)used_group.add(val_not_group[1])heappush(used, (-val_used_group[0],val_used_group[1]))#print(score)if i+1 in dic:ans += score*dic[i+1]#print(L)print(ans)if __name__ == '__main__':main()