classSolution { public: vector<int> maxSubsequence(vector<int>& nums, int k){ vector<int> cc = nums; sort(cc.begin(), cc.end(), greater<int>()); unordered_map<int, int> cnt; int n = nums.size(); for (int i = 0; i < k; i ++ ) cnt[cc[i]] += 1; vector<int> ret; for (int i = 0; i < n; i ++ ) { if (cnt[nums[i]] > 0) { cnt[nums[i]] -= 1; ret.push_back(nums[i]); } } return ret; } };
classSolution { public: vector<int> goodDaysToRobBank(vector<int>& nums, int time){ int n = nums.size(); vector<int> L(n, 0), R(n, 0); for (int i = 1; i < n; i ++ ) { if (nums[i] <= nums[i - 1]) L[i] = L[i - 1] + 1; } for (int i = n - 2; i >= 0; i -- ) { if (nums[i] <= nums[i + 1]) R[i] = R[i + 1] + 1; } vector<int> ret; for (int i = 0; i < n; i ++ ) { if (i - time >= 0and i + time < n) { if (L[i] >= time and R[i] >= time) ret.push_back(i); } } return ret; } };