1846.cpp (445B)
1 class Solution { 2 public: 3 int maximumElementAfterDecrementingAndRearranging(const vector<int> &arr) const { 4 static int count[100001]; 5 memset(count, 0x00, sizeof(count)); 6 7 const int n = size(arr); 8 for (const int num : arr) 9 count[min(num, n)]++; 10 11 int res = 1; 12 for (int num = 2; num <= n; num++) { 13 res = min(res + count[num], num); 14 } 15 return res; 16 } 17 };