結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー beetbeet
提出日時 2018-11-13 19:53:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 985 bytes
コンパイル時間 2,001 ms
コンパイル使用メモリ 200,712 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2023-08-26 00:52:33
合計ジャッジ時間 6,652 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 24 ms
4,376 KB
testcase_14 AC 26 ms
4,376 KB
testcase_15 AC 67 ms
5,004 KB
testcase_16 AC 111 ms
6,260 KB
testcase_17 AC 115 ms
6,528 KB
testcase_18 AC 20 ms
4,380 KB
testcase_19 AC 151 ms
7,216 KB
testcase_20 AC 54 ms
4,676 KB
testcase_21 AC 151 ms
7,328 KB
testcase_22 AC 56 ms
4,620 KB
testcase_23 AC 151 ms
7,260 KB
testcase_24 AC 37 ms
4,376 KB
testcase_25 AC 151 ms
7,316 KB
testcase_26 AC 18 ms
4,376 KB
testcase_27 AC 113 ms
6,204 KB
testcase_28 AC 103 ms
6,060 KB
testcase_29 AC 59 ms
4,612 KB
testcase_30 AC 156 ms
7,588 KB
testcase_31 AC 23 ms
4,376 KB
testcase_32 AC 25 ms
4,376 KB
testcase_33 AC 167 ms
7,788 KB
testcase_34 AC 164 ms
7,744 KB
testcase_35 AC 166 ms
7,848 KB
testcase_36 AC 159 ms
7,752 KB
testcase_37 AC 167 ms
7,784 KB
testcase_38 AC 163 ms
7,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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<=x) chmax(dp[i+1],dp[x+1]+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;
}
0