C++ solution || simple sorting
\nclass Solution\n{\n    public:\n        int maxCount(vector<int> &b, int n, int maxSum)\n        {\n            int cnt = 0;\n            int sum = 0;\n      
```\nclass Solution\n{\n    public:\n        int maxCount(vector<int> &b, int n, int maxSum)\n        {\n            int cnt = 0;\n            int sum = 0;\n            int i = 0;\n            sort(b.begin(), b.end());\n            for (int val = 1; val <= n; val++)\n            {\n                if (i < b.size() and val == b[i])\n                    while (i < b.size() and val == b[i])\n                        i++;\n                else\n                {\n                    if (val + sum <= maxSum)\n                    {\n                        cnt++;\n                        sum += val;\n                    }\n                    else return cnt;\n                }\n            }\n            return cnt;\n        }\n};\n```
['Sorting']