[Programmers] 야근 지수 - Python
·
알고리즘/프로그래머스
난이도: Lv. 3 문제 설명회사원 Demi는 가끔은 야근을 하는데요, 야근을 하면 야근 피로도가 쌓입니다. 야근 피로도는 야근을 시작한 시점에서 남은 일의 작업량을 제곱하여 더한 값입니다. Demi는 N시간 동안 야근 피로도를 최소화하도록 일할 겁니다.Demi가 1시간 동안 작업량 1만큼을 처리할 수 있다고 할 때, 퇴근까지 남은 N 시간과 각 일에 대한 작업량 works에 대해 야근 피로도를 최소화한 값을 리턴하는 함수 solution을 완성해주세요. 제한 사항works는 길이 1 이상, 20,000 이하인 배열입니다.works의 원소는 50000 이하인 자연수입니다.n은 1,000,000 이하인 자연수입니다. 문제 예제worksnresult[4, 3, 3]412[2, 1, 2]16[1, 1]30 입..
[Programmers] 테이블 해시 함수 - Python
·
알고리즘/프로그래머스
난이도: Lv. 2 문제 설명완호가 관리하는 어떤 데이터베이스의 한 테이블은 모두 정수 타입인 컬럼들로 이루어져 있습니다. 테이블은 2차원 행렬로 표현할 수 있으며 열은 컬럼을 나타내고, 행은 튜플을 나타냅니다.첫 번째 컬럼은 기본키로서 모든 튜플에 대해 그 값이 중복되지 않도록 보장됩니다. 완호는 이 테이블에 대한 해시 함수를 다음과 같이 정의하였습니다.해시 함수는 col, row_begin, row_end을 입력으로 받습니다.테이블의 튜플을 col번째 컬럼의 값을 기준으로 오름차순 정렬을 하되, 만약 그 값이 동일하면 기본키인 첫 번째 컬럼의 값을 기준으로 내림차순 정렬합니다.정렬된 데이터에서 S_i를 i 번째 행의 튜플에 대해 각 컬럼의 값을 i 로 나눈 나머지들의 합으로 정의합니다.row_begi..
[LeetCode] 2064. Minimized Maximum of Products Distributed to Any Store - Python
·
알고리즘/LeetCode
문제 설명You are given an integer n indicating there are n specialty retail stores. There are m product types of varying amounts, which are given as a 0-indexed integer array quantities, where quantities[i] represents the number of products of the ith product type. You need to distribute all products to the retail stores following these rules:A store can only be given at most one product type but ca..
[LeetCode] 2563. Count the Number of Fair Pairs - Python
·
알고리즘/LeetCode
문제 설명Given a 0-indexed integer array nums of size n and two integers lower and upper, return the number of fair pairs.A pair (i, j) is fair if:0 , andlower  문제 예제Example 1:Input: nums = [0,1,7,4,4,5], lower = 3, upper = 6Output: 6Explanation: There are 6 fair pairs: (0,3), (0,4), (0,5), (1,3), (1,4), and (1,5). Example 2:Input: nums = [1,7,9,2,5], lower = 11, upper = 11Output: 1Explanation: Ther..