結果
問題 | No.2591 安上がりな括弧列 |
ユーザー |
👑 ![]() |
提出日時 | 2023-12-19 14:06:46 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 501 bytes |
コンパイル時間 | 2,056 ms |
コンパイル使用メモリ | 197,888 KB |
最終ジャッジ日時 | 2025-02-18 12:15:13 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <bits/stdc++.h>#pragma GCC optimize("unroll-loops")using namespace std;using ll=long long;#define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++)//O(N log(N))int main() {ios::sync_with_stdio(false);cin.tie(nullptr);int N;cin>>N;priority_queue<ll> pq;ll ans=0;string S;cin>>S;rep(i,0,N*2){ll a;cin>>a;if(S[i]=='('){ans+=a;pq.push(a);}else{pq.push(-a);}if(i%2==0){ans-=pq.top();pq.pop();}}cout<<ans<<"\n";}