forked from tatyam-prime/SortedSet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathABC281-E.py
More file actions
33 lines (29 loc) · 671 Bytes
/
Copy pathABC281-E.py
File metadata and controls
33 lines (29 loc) · 671 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# https://atcoder.jp/contests/abc281/submissions/46930602
# paste SortedMultiset here
import sys
input = sys.stdin.readline
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
first = sorted(A[:M])
low = SortedMultiset(first[:K])
high = SortedMultiset(first[K:])
ans = sum(first[:K])
print(ans)
for i in range(M, N):
x = A[i]
if x < low[-1]:
ans -= low[-1]
high.add(low.pop(-1))
ans += x
low.add(x)
else:
high.add(x)
x = A[i - M]
if x < high[0]:
ans -= x
low.discard(x)
ans += high[0]
low.add(high.pop(0))
else:
high.discard(x)
print(ans)