ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 15748 |
문제명 | Rest Stops |
레벨 | 골드 5 |
분류 |
그리디 |
시간복잡도 | O(n) |
인풋사이즈 | n<=10^5 |
사용한 언어 | Python |
제출기록 | 46980KB / 184ms |
최고기록 | 184ms |
해결날짜 | 2022/04/13 |
"""Solution code for "BOJ 15748. Rest Stops".
- Problem link: https://www.acmicpc.net/problem/15748
- Solution link: http://www.teferi.net/ps/problems/boj/15748
Tags: [Greedy]
"""
import sys
import operator
def main():
# pylint: disable=unused-variable
L, N, rF, rB = [int(x) for x in sys.stdin.readline().split()]
stops = [[int(x) for x in sys.stdin.readline().split()] for _ in range(N)]
answer = 0
prev_pos = 0
for pos, tastiness in sorted(stops,
key=operator.itemgetter(1),
reverse=True):
if pos > prev_pos:
answer += tastiness * (rF - rB) * (pos - prev_pos)
prev_pos = pos
print(answer)
if __name__ == '__main__':
main()
"""Solution code for "BOJ 15748. Rest Stops".
- Problem link: https://www.acmicpc.net/problem/15748
- Solution link: http://www.teferi.net/ps/problems/boj/15748
Tags: [Greedy]
"""
import itertools
import sys
INF = float('inf')
def main():
# pylint: disable=unused-variable
L, N, rF, rB = [int(x) for x in sys.stdin.readline().split()]
stops = [[int(x) for x in sys.stdin.readline().split()] for _ in range(N)]
stops_to_rest = []
max_tastiness = 0
for pos, tastiness in reversed(stops):
if tastiness > max_tastiness:
max_tastiness = tastiness
stops_to_rest.append((pos, tastiness))
stops_to_rest.append((0, INF))
speed_diff = rF - rB
answer = sum(s2[1] * (s2[0] - s1[0]) * speed_diff
for s1, s2 in itertools.pairwise(reversed(stops_to_rest)))
print(answer)
if __name__ == '__main__':
main()