Mini
[맞음] 프로그래머스 서버증설횟수 // 배열, 구현 본문
https://school.programmers.co.kr/learn/courses/30/lessons/389479
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
* 풀이
필요할때마다 증설하는게 최적인가? 그런듯.
귀류법 증명) ...
class Solution {
static int[] need = new int[25];
static int[] server = new int[25];
public int solution(int[] players, int m, int k) {
int answer = 0;
int n = players.length;
for(int i=0;i<players.length;++i){
need[i] = players[i]/m;
}
// for(int i=0;i<n;++i){
// System.out.print(need[i]+" ");
// }
for(int i=0;i<n;++i){
if(need[i]>server[i]){
int gab = Math.abs(need[i]-server[i]);
for(int j=0;j<k;++j){
if(i+j>=n) break;
server[i+j]+=gab;
}
answer+=gab;
}
}
return answer;
}
}
'Algorithm > 배열' 카테고리의 다른 글
[틀림] 프로그래머스 자물쇠와 열쇠 // 배열회전, 배열좌표 (0) | 2025.04.04 |
---|---|
[틀림] 프로그래머스 외벽점검 // 원형배열, 순열 (0) | 2025.03.31 |
[알고리즘] 리트코드 238. Product of Array Except Self c++ // 배열, 누적곱, rbegin, partial_sum (0) | 2024.07.02 |
리트코드 자기를 제외한 배열의 곱 c++ // 누적곱 해결방법 : 누적곱 테이블을 정의하라 (0) | 2024.05.18 |
백준 13458 시험감독 c++ // ret는 int범위를넘을수있다. (0) | 2024.02.16 |