結果
| 問題 |
No.2808 Concentration
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-07-12 21:50:25 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 83 ms / 2,000 ms |
| コード長 | 777 bytes |
| コンパイル時間 | 878 ms |
| コンパイル使用メモリ | 76,120 KB |
| 実行使用メモリ | 12,268 KB |
| 最終ジャッジ日時 | 2024-07-12 21:50:33 |
| 合計ジャッジ時間 | 7,827 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 57 |
ソースコード
#include<iostream>
#include<deque>
#include<vector>
#include<cassert>
using namespace std;
int N,S,H;
int L[2<<17],R[2<<17],Z[2<<17];
long dp[2<<17],ZS[2<<17];
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>N>>S>>H;
L[0]=R[0]=-H;
long zs=0;
for(int i=1;i<=N;i++)
{
cin>>L[i]>>R[i]>>Z[i];
zs+=Z[i];
ZS[i+1]=ZS[i]+Z[i];
dp[i]=1e18;
}
deque<pair<int,long> >Q;
int l=0;
long mx=0;
for(int i=1;i<=N;i++)
{
dp[i]=dp[i-1]+Z[i];
while(R[l+1]+H<=L[i])l++;
pair<int,long>t=make_pair(L[i],dp[l]+ZS[i]-ZS[l+1]);
while(!Q.empty()&&Q.back().second>=t.second)Q.pop_back();
Q.push_back(t);
while(!Q.empty()&&Q.front().first+S<R[i])Q.pop_front();
if(!Q.empty())dp[i]=min(dp[i],Q.front().second);
mx=max(mx,dp[i]);
}
cout<<zs-mx<<endl;
}