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;
- ll k=0;
- multiset <ll> s;
- s.insert(0);
- for (ll i=1; i<=n; i++){
- ll x;
- cin>>x;
- if (x!=0) s.insert(x);
- else {
- auto it=s.end(); it--;
- k+=(*it);
- s.erase(s.find(*it));
- }
- }
- cout<<k<<"\n";
- }
- int main()
- {
- int t;
- cin>>t;
- while(t--){
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement