fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. ios::sync_with_stdio(false);
  6. cin.tie(NULL);
  7.  
  8. multiset<long long> s;
  9. string a;
  10.  
  11. while(cin >> a){
  12. if(a[0] == '+'){
  13. long long b = stoll(a.substr(1));
  14. if(s.size() < 15000) s.insert(b);
  15. }
  16. else{
  17. if(!s.empty()){
  18. long long b = *s.rbegin();
  19. s.erase(b);
  20. }
  21. }
  22. }
  23.  
  24. cout << s.size() << "\n";
  25. for(auto it = s.rbegin(); it != s.rend(); ++it)
  26. cout << *it << "\n";
  27.  
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0.01s 5320KB
stdin
+1
+3
+2
+3
-
+4
+4
-
+2
+90
+77
+82
-
stdout
5
82
77
2
2
1