-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path26-39.cpp
More file actions
39 lines (32 loc) · 924 Bytes
/
26-39.cpp
File metadata and controls
39 lines (32 loc) · 924 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
35
36
37
38
39
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
using namespace std;
int main() {
fstream f;
f.open("26-39.txt");
vector<int> rangeFiltered, others;
int remaining, n, x, count = 0;
f >> remaining >> n;
for (int i = 0; i < n; ++i) {
f >> x;
if (x > 179 && x < 201)
rangeFiltered.push_back(x);
else
others.push_back(x);
}
sort(rangeFiltered.begin(), rangeFiltered.end());
sort(others.rbegin(), others.rend());
while (!rangeFiltered.empty() && remaining - rangeFiltered.back() >= 0) {
remaining -= rangeFiltered.back();
rangeFiltered.pop_back();
++count;
}
while (!others.empty() && remaining - others.back() >= 0) {
remaining -= others.back();
others.pop_back();
++count;
}
cout << count << " ";
}