[백준] 11399, 11651 - Python3
11651. 좌표 정렬하기 2
https://www.acmicpc.net/problem/11651
내 풀이 - 성공
from sys import stdin
N = int(stdin.readline())
coords = []
for _ in range(N):
x, y = map(int, stdin.readline().split())
coords.append((x, y))
coords.sort(key = lambda x: (x[1], x[0]))
for x, y in coords:
print(x, y)
입력받은 좌표들을 y 좌표 -> x 좌표 순으로 기준을 잡고 정렬
11399. ATM
https://www.acmicpc.net/problem/11399
내 풀이 - 성공
from sys import stdin
N = int(stdin.readline())
P = list(map(int, stdin.readline().split()))
P.sort()
ans = 0
for i in range(N):
ans += P[i] * (N-i)
print(ans)
N = 5
이고 [P1, P2, P3, P4, P5]
의 순서일 때
시간의 합은 P1 * 5 + P2 * 4 + P3 * 3 + P4 * 2 + P5 * 1
이 된다.
여기서 최소 시간합이 되려면 상대적으로 큰 숫자를 곱하는 앞 순서의 P 값들이 작아야 한다.
따라서 정렬 후 P * N-i
를 모두 더해주면 된다.
Author And Source
이 문제에 관하여([백준] 11399, 11651 - Python3), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@jsh5408/백준-11286-11651-Python3저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)