-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday4.cpp
More file actions
34 lines (30 loc) · 808 Bytes
/
day4.cpp
File metadata and controls
34 lines (30 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int maxItems(int n, int maxSum, int banned[], int bannedSize) {
bool isBanned[10001] = {false};
for (int i = 0; i < bannedSize; i++) {
isBanned[banned[i]] = true;
}
int count = 0, currentSum = 0;
for (int i = 1; i <= n; i++) {
if (!isBanned[i] && currentSum + i <= maxSum) {
currentSum += i;
count++;
} else if (currentSum + i > maxSum) {
break;
}
}
return count;
}
int main() {
int n, maxSum, bannedSize;
cin >> n >> maxSum >> bannedSize;
int banned[bannedSize];
for (int i = 0; i < bannedSize; i++) {
cin >> banned[i];
}
cout << maxItems(n, maxSum, banned, bannedSize) << endl;
return 0;
}