<jupyter_start><jupyter_text>Greedy 알고리즘 문제 풀이  2022-03-01  2839 설탕 배달<jupyter_code>N = int(input())
b_sum = 0

while N >= 0:
    if N%5 == 0:
        b_sum += N//5
        print(b_sum)
        break
    else:
        N -= 3
        b_sum += 1
else:
    print(-1)<jupyter_output><empty_output><jupyter_text>2022-03-02  11399번 ATM<jupyter_code>N = int(input())
time_list = list(map(int, input().split()))
time_total = 0

time_list.sort(reverse = True)

for i, time in enumerate(time_list):
    time_total += (i+1)*time

print(time_total)<jupyter_output><empty_output><jupyter_text>2022-03-03  11047번 동전 0<jupyter_code>N, K = map(int, input().split())
coin_list = []
coin_sum = 0
for _ in range(N):
    coin_list.append(int(input()))
    
coin_list.sort(reverse = True)

for i in range(len(coin_list)):
    coin_sum += K // coin_list[i]
    K = K % coin_list[i]

print(coin_sum)<jupyter_output><empty_output><jupyter_text>2022-03-04  1931번 회의실배정<jupyter_code>N = int(input())
meeting_list = []

for _ in range(N):
    start, end = list(map(int,input().split()))
    meeting_list.append([start, end])
    
meeting_list = sorted(meeting_list, key = lambda a: a[0])
meeting_list = sorted(meeting_list, key = lambda a: a[1])

last = 0
count = 0

for i, j in meeting_list:
    if i >= last:
        count += 1
        last = j
    else:
        pass

print(count)<jupyter_output><empty_output><jupyter_text>2022-03-05  1026번 보물<jupyter_code>N = int(input())
A_list = list(map(int,input().split()))
B_list = list(map(int,input().split()))
S = 0

A_list.sort()
B_list.sort(reverse = True)

for i in range(N):
    S += A_list[i]*B_list[i]

print(S)<jupyter_output><empty_output><jupyter_text>2022-03-06  1541번 잃어버린 괄호<jupyter_code>n = input().split('-')
sum = 0

for i in n[0].split('+'):
    sum +=int(i)
for i in n[1:]:
    for j in i.split('+'):
        sum -= int(j)

print(sum)<jupyter_output><empty_output><jupyter_text>2022-03-07  5585번 거스름돈<jupyter_code>price = int(input())
changes_list = [500, 100, 50, 10, 5, 1]
cost = 1000 - price
count_changes = 0
t = 0

for change in changes_list:
    if cost // change >= 1:
        t = cost // change
        cost -= change * t
        count_changes += t
    else:
        pass

print(count_changes)<jupyter_output><empty_output><jupyter_text>2022-03-08  2217번 로프<jupyter_code>N = int(input()
rope_list = []
rope_list2 = []

for i in range(N):
    rope_list.append(int(input()))
rope_list.sort(reverse = True)

for i, t in enumerate(rope_list):
    rope_list2.append(t*(i+1))

print(max(rope_list2))<jupyter_output><empty_output><jupyter_text>2022-03-08  10162번 전자레인지<jupyter_code>T = int(input())
button_list = [300 ,60, 10]
button_push = []
push_time = 0

for button in button_list:
    push_time = T // button
    button_push.append(push_time)
    T -= button*push_time
    
if T == 0:
    print(button_push[0], button_push[1], button_push[2])
else:
    print(-1)<jupyter_output><empty_output><jupyter_text>2022-03-09  10610번 30<jupyter_code>N = list(map(int,input()))
N.sort(reverse = True)

if sum(N) % 3 == 0 and N[-1] == 0:
    for i in N:
        print(i, end = '')
else:
    print(-1)<jupyter_output><empty_output><jupyter_text>2022-03-10  1789번 수들의 합<jupyter_code>S = int(input())
N = 1

while N * (N+1) / 2 <= S:
    N += 1

print(N-1)<jupyter_output><empty_output><jupyter_text>2022-03-11  13305번 주유소<jupyter_code>N = int(input())
road_list = list(map(int, input().split()))
price_list = list(map(int, input().split()))

price = price_list[0]
total_oil = 0

for i in range(N-1):
    if price > price_list[i]:
        price = price_list[i]
    total_oil += price * road_list[i]

print(total_oil)<jupyter_output><empty_output><jupyter_text>2022-03-12  1946번 신입사원<jupyter_code>T = int(input())

for i in range(T):
    count = 1
    people = []
    N = int(input())
    for j in range(N):
        s,m = map(int, input().split())
        people.append([s,m])
        
    people.sort()
    Max = people[0][1]
    
    for i in range(1,N):
        if Max > people[i][1]:
            count += 1
            Max = people[i][1]
            
    print(count)<jupyter_output><empty_output><jupyter_text>2022-03-13  1339번 단어 수학<jupyter_code>N = int(input())

word_list = []
for i in range(N):
    word_list.append(input())
    
dict = {}

for word in word_list:
    sr = len(word) - 1
    for i in word:
        if i in dict:
            dict[i] += pow(10, sr)
        else:
            dict[i] = pow(10,sr)
        sr -= 1

dict = sorted(dict.values(), reverse = True)
n, m = 0, 9

for value in dict:
    n += value * m
    m -= 1
    
print(n)<jupyter_output><empty_output><jupyter_text>2022-03-14  1715번 카드 정렬하기<jupyter_code>import heapq

N = int(input())
card_list = []

for _ in range(N):
    heapq.heappush(card_list, int(input()))
    
if len(card_list) == 1:
    print(0)
else:
    total = 0
    while len(card_list) > 1:
        c1 = heapq.heappop(card_list)
        c2 = heapq.heappop(card_list)
        total += c1 + c2
        heapq.heappush(card_list, c1 + c2)
    print(total)<jupyter_output><empty_output><jupyter_text>2022-03-15  1439번 뒤집기<jupyter_code>S = input()
count0 = 0
count1 = 0

for i in range(len(S)-1):
    if S[i] != S[i+1] and S[i] == '0':
        count0 +=1
    elif S[i] != S[i+1] and S[i] == '1':
        count1 +=1
    else:
        pass

print(max(count0, count1))<jupyter_output><empty_output><jupyter_text>2022-03-16  16953번 A -> B<jupyter_code>A, B = map(int,input().split())
count = 1

while A != B:
    count += 1
    b1 = B
    if B % 10 == 1:
        B //= 10
    elif B % 2 ==0:
        B //= 2
    
    if b1 == B:
        count = -1
        break
    else:
        pass

print(count)<jupyter_output><empty_output><jupyter_text>2022-03-17  4796번 캠핑<jupyter_code>case_num = 1
result = 0

while True:
    L, P, V = map(int, input().split())
    if L + P + V ==0:
        break
    else:
        if V % P > L:
            result = ((V // P) * L) + L
        else:
            result = ((V // P) * L) + (V % P)
        print('Case {}: {}'.format(case_num, result))
        case_num += 1<jupyter_output><empty_output><jupyter_text>2022-03-18  1202번 보석 도둑<jupyter_code>N, K = map(int, input().split())
M_V_list = []
total_price = 0
C_list = []
new_list = []

for _ in range(N):
    M, V = map(int, input().split())
    M_V_list.append([M, V])

for _ in range(K):
    C = int(input())
    C_list.append(C)
C_list.sort()

a_list = [] # 비교 리스트

for C in C_list:
    for M, V in M_V_list:
        if C >= M:
            a_list.append(V)
        else:
            pass

for v in a_list:
    if v not in new_list:
        new_list.append(v)
        
new_list.sort()

for _ in range(K):
    total_price += new_list.pop()

print(total_price)<jupyter_output><empty_output><jupyter_text>2022-03-19  1049번 기타줄<jupyter_code>N, M = map(int,input().split())
p_list = []
i_list = []
total_price = 0

for _ in range(M):
    p, i = map(int, input().split())
    p_list.append(p)
    i_list.append(i)

p = min(p_list)
i = min(i_list)

if p <= i * 6:
    total_price = p * (N // 6) + i * (N % 6)
    if p < i * (N % 6):
        total_price = p * (N // 6 + 1)
else:
    total_price = i * N

print(total_price)<jupyter_output><empty_output><jupyter_text>2022-03-20  1744번 수 묶기<jupyter_code>N = int(input())
number_list = []
sum_n = 0

for _ in range(N):
    number = int(input())
    number_list.append(number)

ne = []
po = []

for number in number_list:
    if number <= 0:
        ne.append(number)
    elif number == 1:
        sum_n += 1
    else:
        po.append(number)

ne.sort()
po.sort(reverse = True)

for i in range(0, len(ne), 2):
    if i+1 < len(ne):
        sum_n += ne[i] * ne[i+1]
    else:
        sum_n += ne[i]

for i in range(0, len(po), 2):
    if i+1 < len(po):
        sum_n += po[i] * po[i+1]
    else:
        sum_n += po[i]

print(sum_n)<jupyter_output><empty_output><jupyter_text>2022-03-21  2864번 5와 6의 차이<jupyter_code>A, B = input().split()

min_A = int(A.replace('6','5'))
min_B = int(B.replace('6','5'))
max_A = int(A.replace('5','6'))
max_B = int(B.replace('5','6'))

print(min_A + min_B, max_A + max_B)<jupyter_output><empty_output><jupyter_text>2022-03-22  1080번 행렬<jupyter_code>N, M = map(int,input().split())
A = []
B = []
count = 0

for _ in range(N):
    A.append(list(map(int,list(input()))))

for _ in range(N):
    B.append(list(map(int,list(input()))))

def clip(x,y):
    for i in range(x, x+3):
        for j in range(y, y+3):
            A[i][j] = 1 - A[i][j]

for x in range(N-2):
    for y in range(M-2):
        if A[x][y] != B[x][y]:
            clip(x,y)
            count += 1

if A != B:
    print(-1)
else:
    print(count)<jupyter_output><empty_output><jupyter_text>2022-03-23  2437번 저울<jupyter_code>N = int(input())
scale_list = list(map(int,input().split()))
number = 1

scale_list.sort()

for scale in scale_list:
    if number < scale:
        break
    else:
        number += scale
        
print(number)<jupyter_output><empty_output><jupyter_text>2022-03-24  1449번 수리공 항승<jupyter_code>N, L = map(int,input().split())
l_list = list(map(int, input().split()))
l_list.sort()

tape = 1
start = l_list[0]
end = start + L - 0.5

for i in l_list:
    if end >= i:
        pass
    else:
        tape += 1
        end = i + L - 0.5

print(tape)<jupyter_output><empty_output><jupyter_text>2022-03-25  1543번 문서검색<jupyter_code>document = input()
word = input()
count = 0
n = 0

for i in range(len(document)):
    if n > i:
        continue
    if word == document[i: i + len(word)]:
        count += 1
        n = i + len(word)
        
print(count)<jupyter_output><empty_output><jupyter_text>2022-03-26  11000번 강의실 배정<jupyter_code>import heapq

N = int(inpput())
class_list = []

for _ in range(N):
    S, T = map(int,input().split())
    class_list.append([S,T])
    
class_list = sorted(class_list, key = lambda a: a[0])

queue = []
heapq.heappush(queue, class_list[0][1])

for i in range(1,N):
    if queue[0] > class_list[i][0]:
        heapq.heappush(queue, class_list[i][1])
    else:
        heapq.heappop(queue)
        heapq.heappush(queue, class_list[i][1])
        
print(len(queue))<jupyter_output><empty_output><jupyter_text>2022-03-27  1783번 병든 나이트<jupyter_code>N, M = map(int,input().split())

if N == 1:
    print(1)
elif N == 2:
    print(min(4, (M + 1) // 2))
else:
    if M <= 6:
        print(min(4, M))
    else:
        print(M - 2)<jupyter_output><empty_output><jupyter_text>2022-03-28  2720번 세탁소 사장 동혁<jupyter_code>T = int(input())

for _ in range(T):
    C = int(input())
    
    q = C //25
    C -= 25*(C//25)
    
    d = C //10
    C -= 10*(C//10)
    
    n = C //5
    C -= 5*(C//5)
    
    p = C
    
    print(q, d, n, p)<jupyter_output><empty_output><jupyter_text>2022-03-29  2847번 게임을 만든 동준이<jupyter_code>N = int(input())
ls_list = []
count = 0

for _ in range(N):
    ls_list.append(int(input()))
    
for i in range(N-2, -1, -1):
    if ls_list[i] >= ls_list[i+1]:
        count += ls_list[i] - ls_list[i+1] + 1
        ls_list[i] = ls_list[i+1] - 1
        
print(count)<jupyter_output><empty_output><jupyter_text>2022-03-30  1700번 멀티탭 스케줄링<jupyter_code>N, K = map(int, input().split())
multitap = list(map(int, input().split()))
plugs = []
count = 0

for i in range(K):
    if multitap[i] in plugs:
        continue
  
    if len(plugs) < N:
        plugs.append(multitap[i])
        continue
  
    multitap_idxs = []

    for j in range(N):
        if plugs[j] in multitap[i:]:
            multitap_idx = multitap[i:].index(plugs[j])
        else:
            multitap_idx = 101
        multitap_idxs.append(multitap_idx)

  
    plug_out = multitap_idxs.index(max(multitap_idxs))
    del plugs[plug_out]
    plugs.append(multitap[i])
    count += 1

print(count)<jupyter_output><empty_output><jupyter_text>2022-03-31  3109번 빵집<jupyter_code>def solve(i,j):
    count = 0
    count += 1
    if j == C-1:
        return True
    for d in dx:
        if 0 <= i+d < R and grid[i+d][j+1] == "." and not visit[i+d][j+1]:
            visit[i+d][j+1] = True
            if solve(i+d, j+1):
                return True
    return False

R, C = map(int, input().rstrip("\n").split())
grid = []
visit = [[False]*C for _ in range(R)]
 
for i in range(R):
    grid.append(list(input().rstrip("\n")))
dx = [-1,0,1]
answer = 0
for i in range(R):
    if grid[i][0] == ".":
        if solve(i,0):
            answer+=1

print(answer)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16654568916848134, 'fraction_numerical': 0.050891200903298656, 'mean_word_length': 2.825979635914841, 'pattern_counts': {'":': 1, '<': 140, '<?xml version=': 0, '>': 142, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '32', 'dir': 'jupyter-structured-clean-dedup', 'id': '281854', 'license': 'MIT', 'n_tokens_mistral': 5703, 'n_tokens_neox': 5468, 'n_words': 1083, 'path': 'Greedy.ipynb', 'repo_name': 'junggeun99/Baekjoon_Greedy', 'size': '12399'}