fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5.  
  6. int main(){
  7. ll n , q;
  8. cin>>n>>q;
  9.  
  10. vector<ll> vec(n);
  11. multiset<ll> st;
  12. ll sum = 0 , s = 0;
  13. for(int i=0;i<n;i++){
  14. cin>>vec[i];
  15. st.insert(vec[i]);
  16. sum += vec[i];
  17. }
  18.  
  19. while(q--){
  20. ll t;
  21. cin>>t;
  22.  
  23. if(t == 1){
  24. ll y;
  25. cin>>y;
  26. s += y;
  27. }
  28. else if(t == 2){
  29. ll y;
  30. cin>>y;
  31. st.insert(y + s);
  32. sum += y + s;
  33. }
  34. else{
  35. ll ans = sum , s1 = 0 , c = 0;
  36. vector<ll> v;
  37. for(auto x : st){
  38. if(x > s) break;
  39. v.push_back(x) , s1 += x , c++;
  40. }
  41. ll sz = st.size();
  42. for(int i=0;i<v.size();i++){
  43. st.erase(v[i]);
  44. sum -= v[i];
  45. }
  46. ans -= s1;
  47. ans -= (sz - c) * s;
  48. cout << ans << endl;
  49. }
  50. }
  51. return 0;
  52. }
Runtime error #stdin #stdout #stderr 0.01s 5404KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc