結果

問題 No.1194 Replace
ユーザー lam6er
提出日時 2025-04-15 21:46:12
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 504 bytes
コンパイル時間 219 ms
コンパイル使用メモリ 82,200 KB
実行使用メモリ 103,620 KB
最終ジャッジ日時 2025-04-15 21:47:07
合計ジャッジ時間 10,498 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6 WA * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
operations = []
for _ in range(m):
    b, c = map(int, input().split())
    operations.append((b, c))

# Sort operations by C in descending order
operations.sort(key=lambda x: -x[1])

max_map = {}

for b, c in operations:
    current_b = max_map.get(b, b)
    current_c = max_map.get(c, c)
    if current_c > current_b:
        max_map[b] = current_c

total = n * (n + 1) // 2
sum_diff = 0
for key in max_map:
    sum_diff += (max_map[key] - key)

print(total + sum_diff)
0