-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2244.cpp
39 lines (37 loc) · 1011 Bytes
/
2244.cpp
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
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;
class Solution {
public:
int minimumRounds(vector<int>& tasks) {
unordered_map<int, int> umap;
for (int i = 0; i < tasks.size(); i++) {
umap[tasks[i]]++;
}
int res = 0;
for (auto [_, fre] : umap) {
// cout << "fre" << fre << " with num: " << num << endl;
if (fre == 1) {
return -1;
} else if (fre % 3 == 0) {
res += fre / 3;
} else {
res += fre / 3 + 1;
}
}
return res;
}
};
int main() {
Solution solution;
vector<int> tasks = {2,2,3,3,2,4,4,4,4,4};
int result = solution.minimumRounds(tasks);
if (result != -1) {
cout << "Minimum rounds needed: " << result << endl;
} else {
cout << "It is not possible to complete the tasks following the given rules." << endl;
}
return 0;
}