Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- void solve()
- {
- ll n;
- cin>>n;
- vector <ll> v;
- v.push_back(0);
- ll k=0;
- for (ll i=1; i<=n; i++){
- ll x;
- cin>>x;
- if (x!=0) v.push_back(x);
- else {
- sort(v.begin(),v.end());
- k+=v[v.size()-1];
- if (v[v.size()-1]!=0) v.pop_back();
- }
- }
- cout<<k<<"\n";
- }
- int main()
- {
- int t;
- cin>>t;
- while(t--){
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement