Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- #include <vector>
- int main()
- {
- std::vector<int> arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 5, 3, 2, 1, 6, 8, 3, 2, 1 }; // najwieksze: 9, 8, 8
- std::multiset<int> maxs = { arr[0], arr[1], arr[2] }; // trzy pierwsze elementy
- for (auto it = arr.begin() + 2; it != arr.end(); ++it) {
- if (*it > *maxs.begin()) // aktualna wartosc jest wieksza od najmniejszego elementu w maxs
- {
- maxs.erase(maxs.begin()); // usun najmniejsza wartosc
- maxs.insert(*it); // dodaj aktualna wartosc it
- }
- }
- for (auto x : maxs)
- std::cout << x << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement