結果
問題 |
No.448 ゆきこーだーの雨と雪 (3)
|
ユーザー |
![]() |
提出日時 | 2018-11-13 20:43:45 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 198 ms / 2,000 ms |
コード長 | 966 bytes |
コンパイル時間 | 2,144 ms |
コンパイル使用メモリ | 194,988 KB |
最終ジャッジ日時 | 2025-01-06 16:37:09 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 35 |
ソースコード
#include<bits/stdc++.h> using namespace std; using Int = long long; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} //INSERT ABOVE HERE signed main(){ Int n,k; cin>>n>>k; vector<Int> t(n),d(n); for(Int i=0;i<n;i++) cin>>t[i]>>d[i]; auto check= [&](Int x){ Int lst=-k; for(Int i=0;i<n;i++){ if(d[i]<=x) continue; if(lst+k>t[i]) return 0; lst=t[i]; } return 1; }; Int l=-1,r=1e9+100; while(l+1<r){ Int m=(l+r)>>1; if(check(m)) r=m; else l=m; } cout<<r<<endl; const Int INF = 1e18; Int sum=0; vector<Int> dp(n+1,-INF); dp[0]=0; for(Int i=0,p=0;i<n;i++){ while(t[p]<=t[i]-k) p++; if(!p||t[p-1]<=t[i]-k) chmax(dp[i+1],dp[p]+d[i]); if(d[i]<=r) chmax(dp[i+1],dp[i]); else p=i+1; sum+=d[i]; } cout<<sum-dp[n]<<endl; return 0; }