1296.cpp (590B)
1 class Solution { 2 public: 3 bool isPossibleDivide(const vector<int> &nums, const int k) const { 4 map<int, int> um; 5 for (const int num : nums) 6 um[num]++; 7 for (auto start = begin(um); start != end(um); start++) { 8 const auto [crnt, step] = *start; 9 if (!step) continue; 10 for (int goal = crnt; goal < crnt + k; goal++) { 11 auto it = um.find(goal); 12 if (it == end(um) || it->second < step) return false; 13 it->second -= step; 14 } 15 } 16 return true; 17 } 18 };