专栏文章
题解:AT_abc407_e [ABC407E] Most Valuable Parentheses
AT_abc407_e题解参与者 1已保存评论 0
文章操作
快速查看文章及其快照的属性,并进行相关操作。
- 当前评论
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mimyzkt9
- 此快照首次捕获于
- 2025/12/01 17:51 3 个月前
- 此快照最后确认于
- 2025/12/01 17:51 3 个月前
考虑右括号随便放,反正都是 ,然后左括号尽量选大的,接着因为右括号随便放所以它一定是能够成合法括号序列的,最后显然要使它是合法序列那个右括号不能超过 ,原因显然,不必多说。于是直接用优先队列贪就行了。
代码:
CPP#include<bits/stdc++.h>
using namespace std;
const int N = 4e5+5;
int a[N];
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int _;
cin >> _;
while(_--)
{
int n;
cin >> n;
n<<=1;
for(int i = 1;i<=n;++i)
{
cin >> a[i];
}
priority_queue<int>q;
long long ans = 0;
for(int i = 1;i<=n;++i)
{
q.push(a[i]);
if(q.size()>(i>>1))
{
ans+=q.top();
q.pop();
}
}
cout << ans << '\n';
}
return 0;
}
相关推荐
评论
共 0 条评论,欢迎与作者交流。
正在加载评论...