본문 바로가기
python-algorithm

백준 3985 롤 케이크

by 무적김두칠 2022. 10. 28.

https://www.acmicpc.net/problem/3985

 

3985번: 롤 케이크

첫째 줄에 롤 케이크의 길이 L (1 ≤ L ≤ 1000)이 주어진다. 둘째 줄에는 방청객의 수 N (1 ≤ N ≤ 1000)이 주어진다. 다음 N개 줄에는 각 방청객 i가 종이에 적어낸 수 Pi와 Ki가 주어진다. (1 ≤ Pi ≤ Ki

www.acmicpc.net

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
l=int(input())+1
nums=[0]*l
n=int(input())
expected_value=0
expected_index=0
for i in range(n):
    p, k = map(int,input().split())
 
    if (k-p) > expected_value:
        expected_index=i+1
        expected_value=k-p
 
    for j in range(p,k+1):
        if nums[j]== 0:
            nums[j]=i+1
counting_sort=[0]*(n+1)
for i in nums:
    if i==0:
        pass
    else:
        counting_sort[i]+=1
 
print(expected_index)
print(counting_sort.index(max(counting_sort)))
cs

첫번째 For 문은 가장 많이 받을거라 기대되는 방청객 구하는 구문이고
두번째 For 문이 계수정렬을 통해 실제로 가장 많이 받게 되는 방청객 구문입니당

First For loop is to find audience who is expected to get most pieces of cake.
Second For loop is to find audience who really will get most pieces of cake, using counting-sort

반응형

'python-algorithm' 카테고리의 다른 글

백준 14696 딱지놀이  (0) 2022.10.28
백준 2947 나무 조각  (0) 2022.10.28
백준 4659 비밀번호 발음하기  (0) 2022.10.27
백준 2303 숫자 게임  (0) 2022.10.27
백준 10174 팰린드롬  (0) 2022.10.27

댓글