-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path230413-2.cpp
More file actions
67 lines (61 loc) · 1.63 KB
/
230413-2.cpp
File metadata and controls
67 lines (61 loc) · 1.63 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct mineral
{
int dia;
int iron;
int stone;
};
bool cmp(mineral &m1, mineral &m2)
{
if(m1.dia != m2.dia) return m1.dia > m2.dia;
if(m1.iron != m2.iron) return m1.iron > m2.iron;
return m1.stone > m2.stone;
}
vector<mineral> scv;
int solution(vector<int> picks, vector<string> minerals) {
int answer = 0;
int diaPick = picks[0], ironPick = picks[1], stonePick = picks[2];
int limit = min(5 * (picks[0] + picks[1] + picks[2]), (int)minerals.size());
int dia = 0, iron = 0, stone = 0;
for(int i = 0; i < limit; i++)
{
if(minerals[i][0] == 'd') dia++;
if(minerals[i][0] == 'i') iron++;
if(minerals[i][0] == 's') stone++;
if(i % 5 == 4)
{
scv.push_back(mineral{dia, iron, stone});
dia = 0; iron = 0; stone = 0;
}
}
if(limit % 5 != 0)
{
scv.push_back(mineral{dia, iron, stone});
}
sort(scv.begin(), scv.end(), cmp);
for(int i = 0;i < scv.size(); i++)
{
// printf("d: %d, iron: %d, stone: %d\n", scv[i].dia, scv[i].iron, scv[i].stone);
if(diaPick > 0)
{
answer += scv[i].dia + scv[i].iron + scv[i].stone;
diaPick--;
continue;
}
if(ironPick > 0)
{
answer += 5 * scv[i].dia + scv[i].iron + scv[i].stone;
ironPick--;
continue;
}
if(stonePick > 0)
{
answer += 25 * scv[i].dia + 5 * scv[i].iron + scv[i].stone;
stonePick--;
}
}
return answer;
}