Submission

Status:
[PPPPPPPP][PPPPPPPP][PPPPPPPPP]

Score: 100

User: hmmm

Problemset: 06.Happiness

Language: cpp

Time: 0.021 second

Submitted On: 2025-04-07 11:55:41

#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
priority_queue<ll,vector<ll>,greater<ll>> q;

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    ll ans=0,sum=0;
    cin >> n;
    for(int i=1;i<=n;i++){
        int x;
        cin >> x;
        if(x>0){
            sum+=x;
            ans++;
        }
        else{
            sum+=x;
            ans++;
            q.push(x);
            if(sum<0){
                sum-=q.top();
                q.pop();
                ans--;
            }
        }
    }
    cout << ans;
}