跳到正文

hjsyh

1655712

666

在洛谷打开
资料、奖项与版本

资料

编号
1655712
抓取

奖项

2026 CSP-J
一等奖

版本

  1. v3当前
  2. v2
  3. v1
C++
#include <bits/stdc++.h>
using namespace std;
long long ans,s,n;
struct T
{
	char x;
	int y;
}a[200100];
priority_queue<int, vector<int>,greater<int> > q;
int main()
{
	freopen("dragons.in","r",stdin);
	freopen("dragons.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
	cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i].x>>a[i].y;
    for(int i=1;i<=n;i++)
	{
        if(a[i].x=='c')
		{
            q.push(a[i].y); 
			s++,ans+=a[i].y;
        } 
		else 
		{
            if(i==n)
			{
                if(s<a[i].y) 
				{
					cout<<-1<<endl; 
					return 0; 
				}
            } 
			else 
			{
                while(s>=a[i].y)
				{
                    ans-=q.top(),s--;
					q.pop();
                }
            }
        }
    }
    cout<<ans<<endl;
}

还没有收录这位用户的文章。