1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#define ll long long
using namespace std;
long long solution(int n, vector<int> works) {
long long answer = 0;
sort(works.begin(),works.end());
int height=works.back();
reverse(works.begin(),works.end());
while(height && n){
for(int i=0;i<works.size();i++){
if(works[i]==height &&n>0){
works[i]--;
n--;
}
else if(works[i]<height)
break;
}
height--;
}
for(int i=0;i<works.size();i++){
answer+=(works[i]*works[i]);
}
return answer;
}
|
cs |
출처: https://school.programmers.co.kr/learn/courses/30/lessons/12927
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
'알고리즘 > 프로그래머스' 카테고리의 다른 글
[c++] 베스트앨범 (해쉬) (0) | 2022.09.23 |
---|---|
[c++] 단속카메라 (그리디, 탐욕법) (0) | 2022.09.23 |
[c++] 양궁대회 (DFS,완전탐색 택1) (0) | 2022.09.21 |
[c++] 셔틀버스 (1) | 2022.09.21 |
[c++] 보석 쇼핑 (1) | 2022.09.20 |