본문 바로가기
반응형

알고리즘/자료구조55

[백준][Python] 13904번 과제 13904번: 과제 예제에서 다섯 번째, 네 번째, 두 번째, 첫 번째, 일곱 번째 과제 순으로 수행하고, 세 번째, 여섯 번째 과제를 포기하면 185점을 얻을 수 있다. www.acmicpc.net 코드 n = int(input()) n_list = [] for _ in range(n): day,score = map(int,input().split()) n_list.append((day,score)) n_list.sort() hw = [] n = n_list[-1][0] ans = 0 for i in range(n,0,-1): while n_list and n_list[-1][0] == i: hw.append(n_list.pop()[1]) hw.sort() if hw: ans += hw.pop() pr.. 2023. 1. 26.
[백준][Python] 10816번 숫자 카드 2 10816번: 숫자 카드 2 첫째 줄에 상근이가 가지고 있는 숫자 카드의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에는 숫자 카드에 적혀있는 정수가 주어진다. 숫자 카드에 적혀있는 수는 -10,000,000보다 크거나 같고, 10, www.acmicpc.net 코드 import sys from collections import defaultdict dic = defaultdict(int) n = int(input()) n_list = list(map(int,sys.stdin.readline().split())) for i in n_list: dic[i] += 1 m = int(input()) m_list = list(map(int,sys.stdin.readline().split())) .. 2023. 1. 25.
[백준][Python] 15903번 카드 합체 놀이 15903번: 카드 합체 놀이 첫 번째 줄에 카드의 개수를 나타내는 수 n(2 ≤ n ≤ 1,000)과 카드 합체를 몇 번 하는지를 나타내는 수 m(0 ≤ m ≤ 15×n)이 주어진다. 두 번째 줄에 맨 처음 카드의 상태를 나타내는 n개의 자연수 a1, www.acmicpc.net 코드 import heapq n,m = map(int,input().split()) n_list = list(map(int,input().split())) heapq.heapify(n_list) for _ in range(m): a = heapq.heappop(n_list) b = heapq.heappop(n_list) heapq.heappush(n_list,a+b) heapq.heappush(n_list,a+b) print(.. 2023. 1. 19.
[백준][Python] 1920번 수 찾기 1920번: 수 찾기 첫째 줄에 자연수 N(1 ≤ N ≤ 100,000)이 주어진다. 다음 줄에는 N개의 정수 A[1], A[2], …, A[N]이 주어진다. 다음 줄에는 M(1 ≤ M ≤ 100,000)이 주어진다. 다음 줄에는 M개의 수들이 주어지는데, 이 수들 www.acmicpc.net 코드 def find(num): f = 0 e = n-1 while f n_list[mid]: f = mid+1 else: e = mid-1 return 0 n = int(input()) n_list = list(map(int,input().split())) n_list.sort() m = int(input()) m_list = list(map(int,input().split())) for i in m_list: .. 2023. 1. 18.
반응형