Advertisement
fooker

P1800C1

Mar 2nd, 2023
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. void solve()
  6. {
  7.     ll n;
  8.     cin>>n;
  9.     vector <ll> v;
  10.     v.push_back(0);
  11.     ll k=0;
  12.     for (ll i=1; i<=n; i++){
  13.         ll x;
  14.         cin>>x;
  15.         if (x!=0) v.push_back(x);
  16.         else {
  17.              sort(v.begin(),v.end());
  18.              k+=v[v.size()-1];
  19.              if (v[v.size()-1]!=0) v.pop_back();
  20.         }
  21.     }
  22.     cout<<k<<"\n";
  23. }
  24.  
  25. int main()
  26. {
  27.     int t;
  28.     cin>>t;
  29.     while(t--){
  30.         solve();
  31.     }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement