목록분류 전체보기 (52)
JH 개발 블로그
from itertools import combinations from collections import Counter def solution(orders, course): answer = [] temp = [] for order in orders: temp.append(sorted(order)) orders = temp for size in course: temp = [] for order in orders: temp += combinations(order,size) temp = Counter(temp).most_common() for menu, cnt in temp: if cnt >= 2 and cnt >= temp[0][1]: answer.append(menu) else: break return s..
import re def solution(new_id): new_id = re.sub('[^a-z\d\-_.]','',new_id.lower()) new_id = re.sub('\.\.+','.',new_id) new_id = re.sub('^\.|\.$','',new_id) if new_id == '': new_id = 'a' new_id = re.sub('\.$','',new_id[:15]) while len(new_id) < 3: new_id += new_id[-1] return new_id 1단계 new_id의 모든 대문자를 대응되는 소문자로 치환합니다. 2단계 new_id에서 알파벳 소문자, 숫자, 빼기(-), 밑줄(_), 마침표(.)를 제외한 모든 문자를 제거합니다. 3단계 new_id에서 마..
import heapq import sys N, K = map(int, sys.stdin.readline().split()) jewelryList = [list(map(int, sys.stdin.readline().split())) for _ in range(N)] bagList = [int(sys.stdin.readline()) for _ in range(K)] jewelryList.sort() bagList.sort() result = 0 temp = [] for bagWeight in bagList: while jewelryList and bagWeight >= jewelryList[0][0]: heapq.heappush(temp, -heapq.heappop(jewelryList)[1]) # Max..
import sys import heapq input = sys.stdin.readline n = int(input()) li = [list(map(int,input().split())) for _ in range(n)] li.sort(key=lambda x:x[1]) temp = [] for p,d in li: heapq.heappush(temp,p) if len(temp) > d: heapq.heappop(temp) print(sum(temp))
n = int(input()) coin = [list(input()) for _ in range(n)] ans = n * n + 1 for bit in range(1
import bisect import sys input = sys.stdin.readline x = int(input()) arr = list(map(int, input().split())) temp = [arr[0]] for i in range(x): if arr[i] > temp[-1]: temp.append(arr[i]) else: idx = bisect.bisect_left(temp, arr[i]) temp[idx] = arr[i] print(len(temp)) 이분탐색 bisect 모듈의 bisect_left 함수를 통해 수열을 계속 수정하면서 답을 구합니다.
n,m = map(int,input().split()) def solution(): if n == 1: return 1 elif n == 2: return min(4,1+(m-1)//2) else: if m