main.cpp (919B)
1 #include <iostream> 2 #include <algorithm> 3 #include <vector> 4 5 int main() { 6 7 int testCount, current, k, numsToLoad; 8 std::cin >> testCount; 9 10 for(int r = 0; r < testCount; ++r) { 11 std::cin >> numsToLoad; 12 std::cin >> k; 13 std::vector<int> nums {}; 14 15 for(int i = 0; i < numsToLoad; ++i) { 16 std::cin >> current; 17 nums.push_back(current); 18 } 19 20 std::sort(nums.begin(), nums.end()); 21 22 int res = -1; 23 int i = 0; 24 25 while(true) { 26 int v = res + 1; 27 bool found = false; 28 29 while(i < nums.size() && nums[i] <= v) { 30 if(nums[i] == v) { 31 found = true; 32 } 33 i += 1; 34 } 35 36 if(!found || i < (v + 1) * k) { 37 break; 38 } 39 40 res = v; 41 } 42 43 std::cout << res + 1 << std::endl; 44 } 45 }