Skip to content

Commit aecc7d4

Browse files
committed
Lv3_야근지수
1 parent 7fa59e5 commit aecc7d4

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <string>
2+
#include <vector>
3+
#include <algorithm>
4+
#include <queue>
5+
using namespace std;
6+
7+
struct work_cmp { // top에 가장 높은 수가 가도록 정렬
8+
bool operator()(int t, int u) {
9+
return t < u;
10+
}
11+
};
12+
13+
long long solution107(int n, vector<int> works) {
14+
long long answer = 0;
15+
priority_queue <int, vector<int>, work_cmp > pq;
16+
for (auto i : works)
17+
pq.push(i);
18+
19+
for (int i = 0; i < n; i++) {
20+
int a = pq.top();
21+
pq.pop();
22+
if (a == 0)
23+
pq.push(0);
24+
else
25+
pq.push(a - 1);
26+
}
27+
28+
while (!pq.empty()) {
29+
answer += pq.top()*pq.top();
30+
pq.pop();
31+
}
32+
return answer;
33+
}

Programmers/Programmers.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
<ClCompile Include="Lv3\Lv3_섬연결하기.cpp" />
113113
<ClCompile Include="Lv3\Lv3_순위.cpp" />
114114
<ClCompile Include="Lv3\Lv3_숫자게임.cpp" />
115+
<ClCompile Include="Lv3\Lv3_야근지수.cpp" />
115116
<ClCompile Include="Lv3\Lv3_여행경로.cpp" />
116117
<ClCompile Include="Lv3\Lv3_예산.cpp" />
117118
<ClCompile Include="Lv3\Lv3_이중우선순위큐.cpp" />
@@ -120,6 +121,7 @@
120121
<ClCompile Include="Lv3\Lv3_정수삼각형.cpp" />
121122
<ClCompile Include="Lv3\Lv3_줄서는방법.cpp" />
122123
<ClCompile Include="Lv3\Lv3_짝지어제거하기.cpp" />
124+
<ClCompile Include="Lv3\Lv3_최고의집합.cpp" />
123125
<ClCompile Include="Lv3\Lv3_카카오프렌즈컬러링북.cpp" />
124126
<ClCompile Include="Lv3\Lv3_캠핑.cpp" />
125127
<ClCompile Include="Lv3\Lv3_타일장식물.cpp" />

Programmers/Programmers.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,5 +342,11 @@
342342
<ClCompile Include="Lv3\Lv3_멀리뛰기.cpp">
343343
<Filter>소스 파일</Filter>
344344
</ClCompile>
345+
<ClCompile Include="Lv3\Lv3_야근지수.cpp">
346+
<Filter>소스 파일</Filter>
347+
</ClCompile>
348+
<ClCompile Include="Lv3\Lv3_최고의집합.cpp">
349+
<Filter>소스 파일</Filter>
350+
</ClCompile>
345351
</ItemGroup>
346352
</Project>

0 commit comments

Comments
 (0)