結果
問題 |
No.448 ゆきこーだーの雨と雪 (3)
|
ユーザー |
![]() |
提出日時 | 2018-11-13 19:52:25 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 175 ms / 2,000 ms |
コード長 | 983 bytes |
コンパイル時間 | 1,747 ms |
コンパイル使用メモリ | 196,104 KB |
最終ジャッジ日時 | 2025-01-06 16:36:44 |
ジャッジサーバーID (参考情報) |
judge3 / 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=-1;i<n;i++){ Int x=upper_bound(t.begin(),t.end(),t[i]-k)-t.begin(); if(p+1<=x) chmax(dp[i+1],dp[x]+d[i]); if(d[i]<=r) chmax(dp[i+1],dp[i]); else p=i; sum+=d[i]; } cout<<sum-dp[n]<<endl; return 0; }