-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path2653.cpp
More file actions
26 lines (24 loc) · 711 Bytes
/
2653.cpp
File metadata and controls
26 lines (24 loc) · 711 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
class Solution {
public:
vector<int> getSubarrayBeauty(vector<int>& nums, int k, int x) {
vector<int> counts(101, 0);
int n = nums.size();
vector<int> res;
for (int i = 0; i < k - 1; ++i) {
counts[nums[i] + 50]++;
}
for (int i = k - 1; i < n; ++i) {
counts[nums[i] + 50]++;
int cum = 0;
int index = 0;
while (cum + counts[index] < x) {
cum += counts[index];
index++;
}
int current = min(0, index - 50);
res.push_back(current);
counts[nums[i - k + 1] + 50]--;
}
return res;
}
};