-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1090.cpp
More file actions
21 lines (19 loc) · 689 Bytes
/
Copy path1090.cpp
File metadata and controls
21 lines (19 loc) · 689 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution {
public:
int largestValsFromLabels(const vector<int> &values, const vector<int> &labels, int numWanted,
int useLimit) {
static int count[20001], idx[20001];
memset(count, 0x00, sizeof(count));
const int n = values.size();
iota(begin(idx), begin(idx) + n, 0);
sort(begin(idx), begin(idx) + n, [&](int a, int b) { return values[a] > values[b]; });
int res = 0;
for (const int i : idx) {
if (count[labels[i]] >= useLimit) continue;
res += values[i];
if (!--numWanted) break;
count[labels[i]]++;
}
return res;
}
};