C++ || TIME O(nlogn) || SPACE (1) || TIME&SPACE 90&98% Beats
\nclass Solution {\npublic:\n    int maxCount(vector<int>& banned, int n, int maxSum) {\n        sort(banned.begin(),banned.end());\n        int i=0,x=0,m = ban
```\nclass Solution {\npublic:\n    int maxCount(vector<int>& banned, int n, int maxSum) {\n        sort(banned.begin(),banned.end());\n        int i=0,x=0,m = banned.size(),ans=0,y=0;\n        for(x = 1; x <= n; x++){\n            if(i<m&&x==banned[i]){\n                while(i<m&&x==banned[i]){\n                    i++;\n                }\n            }else{\n                y += x;\n                if(y<=maxSum){\n                    ans++;\n                }else\n                    break;\n            }\n        }\n        return ans;\n    }\n};\n```
['Array', 'Greedy', 'C', 'Sorting', 'C++']