結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー beetbeet
提出日時 2018-11-13 19:52:25
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 983 bytes
コンパイル時間 1,770 ms
コンパイル使用メモリ 202,036 KB
実行使用メモリ 8,072 KB
最終ジャッジ日時 2023-08-26 00:52:17
合計ジャッジ時間 6,992 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 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 2 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 22 ms
4,380 KB
testcase_14 AC 25 ms
4,384 KB
testcase_15 AC 60 ms
4,844 KB
testcase_16 AC 102 ms
6,156 KB
testcase_17 AC 106 ms
6,516 KB
testcase_18 AC 19 ms
4,380 KB
testcase_19 AC 137 ms
7,156 KB
testcase_20 AC 49 ms
4,704 KB
testcase_21 AC 135 ms
7,316 KB
testcase_22 AC 51 ms
4,624 KB
testcase_23 AC 140 ms
7,148 KB
testcase_24 AC 33 ms
4,380 KB
testcase_25 AC 135 ms
7,388 KB
testcase_26 AC 17 ms
4,384 KB
testcase_27 AC 104 ms
6,096 KB
testcase_28 AC 96 ms
5,932 KB
testcase_29 AC 53 ms
4,672 KB
testcase_30 AC 141 ms
7,460 KB
testcase_31 AC 21 ms
4,384 KB
testcase_32 AC 25 ms
4,380 KB
testcase_33 AC 152 ms
7,792 KB
testcase_34 AC 153 ms
7,740 KB
testcase_35 AC 155 ms
7,848 KB
testcase_36 AC 159 ms
7,744 KB
testcase_37 AC 148 ms
8,072 KB
testcase_38 AC 153 ms
7,680 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+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;
}
0