-
Notifications
You must be signed in to change notification settings - Fork 7
/
3.py
44 lines (34 loc) · 1006 Bytes
/
3.py
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
34
35
36
37
38
39
40
41
42
43
44
import sys
from typing import (
List,
)
class GoldHeap:
__slots__ = ("cost", "count")
def __init__(self, cost: int, count: int):
self.cost: int = cost
self.count: int = count
def __gt__(self, other) -> bool:
return self.cost > other.cost
def __lt__(self, other) -> bool:
return not self.__gt__(other)
def main() -> None:
capacity: int = int(input())
heaps_count: int = int(input())
gold_heaps: List[GoldHeap] = []
for i in range(heaps_count):
c, m = map(int, sys.stdin.readline().rstrip().split())
gold_heaps.append(GoldHeap(cost=c, count=m))
gold_heaps.sort(reverse=True)
max_cost: int = 0
for i in gold_heaps:
if capacity == 0:
break
if capacity >= i.count:
max_cost += i.cost * i.count
capacity -= i.count
else:
max_cost += i.cost * capacity
capacity = 0
print(max_cost)
if __name__ == "__main__":
main()