fork download
  1. #include <iostream>
  2. #include <set>
  3. using namespace std;
  4.  
  5. int main() {
  6. // your code goes here
  7. multiset<int> s{1, 1, 1, 3, 4, 5};
  8.  
  9. int n = 5;
  10. int idx = 0;
  11. auto it = s.begin();
  12. while(idx < n - 1){
  13. idx++;
  14. cout << *it << " ";
  15. it++;
  16. }
  17. it--;
  18. cout << *it << "\n";
  19.  
  20. s.insert(2);
  21. it--;
  22. cout << *it << "\n";
  23. return 0;
  24. }
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
1 1 1 3 3
2