結果
問題 |
No.2321 Continuous Flip
|
ユーザー |
|
提出日時 | 2023-05-26 22:41:24 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 678 bytes |
コンパイル時間 | 958 ms |
コンパイル使用メモリ | 78,044 KB |
実行使用メモリ | 19,712 KB |
最終ジャッジ日時 | 2024-12-25 08:59:48 |
合計ジャッジ時間 | 8,390 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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++) { while(!Q.empty()&&Q.top().second<i)Q.pop(); if(!Q.empty())dp[i]=max(dp[i],2*S[i]+Q.top().first); if(i<N)dp[i+1]=max(dp[i+1],dp[i]); for(int r:G[i])Q.push(make_pair(dp[i]-S[r]-S[i]-C,r)); //cout<<dp[i]<<" "; } //cout<<endl; cout<<dp[N]<<endl; }