結果
問題 |
No.2321 Continuous Flip
|
ユーザー |
|
提出日時 | 2023-05-26 22:43:18 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 729 bytes |
コンパイル時間 | 863 ms |
コンパイル使用メモリ | 78,088 KB |
実行使用メモリ | 19,824 KB |
最終ジャッジ日時 | 2024-12-25 09:06:01 |
合計ジャッジ時間 | 8,478 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 9 WA * 21 |
ソースコード
#include<iostream> #include<vector> #include<queue> using namespace std; int N,M,C; int A[2<<17]; long S[2<<17]; vector<int>G[2<<17]; long dp[2<<17]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin>>N>>M>>C; for(int i=0;i<N;i++) { cin>>A[i]; S[i+1]=S[i]+A[i]; } for(int i=0;i<M;i++) { int l,r;cin>>l>>r; G[l-1].push_back(r); } priority_queue<pair<long,int> >Q; for(int i=0;i<=N;i++) { if(i<N)dp[i+1]=max(dp[i+1],dp[i]); long v=dp[i]; while(!Q.empty()&&Q.top().second<i)Q.pop(); if(!Q.empty())v=max(v,2*S[i]+Q.top().first); for(int r:G[i]) { Q.push(make_pair(v-S[r]-S[i]-C,r)); dp[r]=max(dp[r],v+S[r]-S[i]-C); } //cout<<dp[i]<<" "; } //cout<<endl; cout<<dp[N]<<endl; }