結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー beetbeet
提出日時 2018-11-13 20:43:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 966 bytes
コンパイル時間 1,713 ms
コンパイル使用メモリ 202,036 KB
実行使用メモリ 7,924 KB
最終ジャッジ日時 2023-08-26 00:53:35
合計ジャッジ時間 5,931 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,356 KB
testcase_03 AC 1 ms
4,356 KB
testcase_04 AC 2 ms
4,356 KB
testcase_05 AC 2 ms
4,360 KB
testcase_06 AC 2 ms
4,356 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,356 KB
testcase_09 AC 2 ms
4,356 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 1 ms
4,356 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 20 ms
4,356 KB
testcase_14 AC 23 ms
4,352 KB
testcase_15 AC 56 ms
4,840 KB
testcase_16 AC 94 ms
6,244 KB
testcase_17 AC 102 ms
6,588 KB
testcase_18 AC 17 ms
4,356 KB
testcase_19 AC 136 ms
7,532 KB
testcase_20 AC 48 ms
4,676 KB
testcase_21 AC 130 ms
7,220 KB
testcase_22 AC 48 ms
4,552 KB
testcase_23 AC 129 ms
7,368 KB
testcase_24 AC 31 ms
4,356 KB
testcase_25 AC 130 ms
7,236 KB
testcase_26 AC 17 ms
4,352 KB
testcase_27 AC 96 ms
6,276 KB
testcase_28 AC 93 ms
6,216 KB
testcase_29 AC 52 ms
4,576 KB
testcase_30 AC 135 ms
7,496 KB
testcase_31 AC 19 ms
4,356 KB
testcase_32 AC 22 ms
4,352 KB
testcase_33 AC 142 ms
7,924 KB
testcase_34 AC 146 ms
7,816 KB
testcase_35 AC 143 ms
7,912 KB
testcase_36 AC 146 ms
7,916 KB
testcase_37 AC 147 ms
7,804 KB
testcase_38 AC 145 ms
7,832 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=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;
}
0