-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_172927.java
More file actions
49 lines (47 loc) · 1.57 KB
/
_172927.java
File metadata and controls
49 lines (47 loc) · 1.57 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.*;
class Solution {
static PriorityQueue<Integer> M = new PriorityQueue<>(Collections.reverseOrder());
public int solution(int[] picks, String[] minerals) {
initMinerals(minerals, picks[0]+picks[1]+picks[2]);
int result = 0;
for(int i=0; i<3; i++){
for(; picks[i]>0; picks[i]--){
result += getTired(i, M.poll());
if(M.isEmpty()) break;
}
if(M.isEmpty()) break;
}
return result;
}
public void initMinerals(String[] m, int pickCnt){
// 100:diamond, 10:iron, 1:stone
int value = 0;
for(int i=0; i<m.length; i++){
if(i>0 && i%5==0){
M.add(value);
value = 0;
// 곡괭이의 수가 모든 광물을 캐기에 모자랄 때
if(M.size()==pickCnt) return;
}
switch(m[i]){
case "diamond" : value+=100; break;
case "iron" : value+=10; break;
case "stone" : value+=1; break;
default : break;
}
}
M.add(value);
}
public int getTired(int pick, int value){
int diamond = value/100;
int iron = value%100/10;
int stone = value%10;
// System.out.println(diamond+","+iron+","+stone);
switch(pick){
case 0 : return diamond + iron + stone;
case 1 : return diamond*5 + iron + stone;
case 2 : return diamond*25 + iron*5 + stone;
default : return -1;
}
}
}