結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー dohatsutsudohatsutsu
提出日時 2016-11-19 00:09:40
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,563 bytes
コンパイル時間 1,504 ms
コンパイル使用メモリ 161,612 KB
実行使用メモリ 11,352 KB
最終ジャッジ日時 2024-05-04 19:13:05
合計ジャッジ時間 3,868 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:72:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   72 |   scanf("%lld %lld",&N,&K);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~
main.cpp:74:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   74 |     scanf("%lld %lld",&a[i],&b[i]);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

typedef pair<ll,ll> P;
#define MAX_N 200005

vector<ll> X;
ll N,K;
ll a[MAX_N],b[MAX_N];
ll c[MAX_N];
ll d[MAX_N];

ll INF = (1LL<<60);
ll tree[500];

ll getMax(int l,int r){
  ll res=-INF;
  int i=l;
  while(i<r){
    if(i%500==0&& i+500<r){
      res=max(res,tree[i/500]);
      i+=500;
    }else{
      res=max(res,b[i]);
      i++;
    }
  }
  return res;
}

void update(int i,ll x){
  tree[i/500]=max(tree[i/500],x);
}

ll getSum(int l,int r){
  if(r<=l)return 0;
  return c[r]-c[l];
}

ll solve(ll x){
  fill(d,d+MAX_N, INF );  
  d[0]=0;
  for(int i=0;i<N;i++){
    if(d[i]== INF)continue;
    ll sum=d[i];
    
    if( b[i]<=x ){
      d[i+1]=min(d[i+1], sum+b[i] );
    }
    int target=lower_bound( X.begin(),X.end(),a[i]+K)-X.begin();
    if( getMax(i+1,target) <= x )
      d[target]=min(d[target], sum+getSum(i+1,target) );
  }
  return d[N]; 
}

bool check(ll x){
  ll last=0;
  for(int i=0;i<N;i++){
    if(b[i]>x){
      if(last>a[i])return false;
      last=a[i]+K;
    }
  }
  return true;
}

int main(){
  fill(tree,tree+500, -INF );
  
  scanf("%lld %lld",&N,&K);
  for(int i=0;i<N;i++){
    scanf("%lld %lld",&a[i],&b[i]);
    update( i , b[i] );
    X.push_back(a[i]);
    if(i>0)
      assert(a[i]>a[i-1]);
  }
  X.push_back( INF );
  for(int i=0;i<N;i++)c[i+1]=c[i]+b[i];
  ll left=0,right=1e9+1,mid;
  while(right-left>1){
    mid=(left+right)/2;
    if(check(mid))left=mid;
    else right=mid;
  }
  printf("%lld\n",left);
  printf("%lld\n",solve(left));
  return 0;
}
0