-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.cc
More file actions
34 lines (31 loc) · 689 Bytes
/
test.cc
File metadata and controls
34 lines (31 loc) · 689 Bytes
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
#include <vector>
#include <iostream>
#include <map>
using namespace std;
class Solution {
public:
int B;
int solve(int s, vector<int> &f) {
int ans = 0;
for (int &x : f) {
if (x) {
ans = max(ans, (s % B ? 0 : 1) + solve(s + x--, f));
x++;
}
}
return ans;
}
int maxHappyGroups(int B, vector<int>& groups) {
this->B = B;
vector<int> f(B);
for (int g : groups) {
f[g%B]++;
}
return solve(0, f);
}
};
int main() {
vector<int> g = {1, 2, 3, 4, 5, 6};
auto ans = Solution().maxHappyGroups(3, g);
cout << ans << endl;
}