classSolution { public: vector<int> smallestK(vector<int>& arr, int k){ if (k == 0) return {}; int l = partition(arr, 0, arr.size() - 1, k); returnvector<int>(arr.begin(), arr.begin() + l + 1); } intpartition(vector<int>& a, int l, int r, int k){ if (l == r) return l; int mid = l + r >> 1; int p = a[mid]; int i = l - 1, j = r + 1; while (i < j) { while (a[++i] < p); while (a[--j] > p); if (i < j) swap(a[i], a[j]); } int sl = j - l + 1; if (k <= sl) returnpartition(a, l, j, k); else returnpartition(a, j + 1, r, k - sl); } };