結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー dohatsutsudohatsutsu
提出日時 2016-11-18 23:59:15
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,415 bytes
コンパイル時間 1,146 ms
コンパイル使用メモリ 163,408 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-04 19:06:54
合計ジャッジ時間 8,201 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

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


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]);
    assert(i>0 && a[i]>a[i-1]);
  }
  X.push_back( INF );
  for(int i=0;i<N;i++)c[i+1]=c[i]+b[i];
  P ans=solve();
  cout<<(int)ans.first<<endl;
  cout<<(int)ans.second<<endl;
  return 0;
}
0