Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Git
- QuerySet
- to_attr
- dry-yasg
- CD
- DRF
- aws
- 백준
- EC2
- database
- Continuous Deployment
- 도커
- F객체
- racecondition
- CI
- docker
- Python
- apitestcase
- Continuous Delivery
- annotate
- Transaction
- testcase
- DjangoCache
- 코루틴
- DjangoRestFramework
- nestedfunction
- aggregate
- Coroutine
- Prefetch_related
- django
Archives
- Today
- Total
BackEnd King KY
백준 1931 본문
728x90

✔️문제
https://www.acmicpc.net/problem/1931
1931번: 회의실 배정
(1,4), (5,7), (8,11), (12,14) 를 이용할 수 있다.
www.acmicpc.net
✔️풀이
n = int(input())
l = []
for i in range(n):
l.append(list(map(int, input().split())))
l = sorted(l, key=lambda a:a[0])
l = sorted(l, key=lambda a:a[1])
cnt = 0
base = 0
for i,j in l:
if i >= base:
base = j
cnt +=1
print(cnt)
정렬 방법에 대해 찾아봤는데 sorted에서 key=lamda a:a[0] 이렇게 하면 a[0] 기준으로 정렬할 수 있다고 합니다. a:a[1]이면 a[1]기준으로 정렬을 한다는 뜻이 되는 것입니다.
그래서 앞 순서에 맞게 정렬 한 뒤, 정렬된 리스트에서 뒷 순서에 맞게 정렬을 하게 되는 것입니다.
base는 가능한 a[1] 값을 넣기위한 변수이며, a[0]이 base보다 크거나 같다면 회의 시간이 갱신될 수 있기 때문에 cnt를 +1 해주게 되는 것입니다.