2554.cpp (389B)
1 class Solution { 2 public: 3 int maxCount(const vector<int> &banned, int n, int maxSum) const { 4 unordered_set<int> us(begin(banned), end(banned)); 5 6 int res = 0, sum = 0; 7 for (int i = 1; i <= n; i++) { 8 if (us.count(i)) continue; 9 sum += i; 10 if (sum > maxSum) return res; 11 res++; 12 } 13 14 return res; 15 } 16 };