結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー dohatsutsudohatsutsu
提出日時 2016-11-18 23:11:08
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,332 bytes
コンパイル時間 1,329 ms
コンパイル使用メモリ 162,652 KB
実行使用メモリ 817,408 KB
最終ジャッジ日時 2024-05-04 18:45:49
合計ジャッジ時間 3,892 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

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

ll INF = (1LL<<50);

ll tree[(1<<18)];

ll getMax(int a,int b,int k=0,int l=0,int r=(1<<17)){
  if(b<=l || r<=a)return -INF;
  if(a<=l && b<=r)return tree[k];
  int m=(l+r)/2;
  return max( getMax(a,b,k*2+1,l,m) , getMax(a,b,k*2+2,m,r) );
}

void update(int i,ll x){
  i+=(1<<17)-1;
  tree[i]=x;
  while(i){
    i=(i-1)/2;
    tree[i]=max(tree[i*2+1],tree[i*2+2]);
  }
}

ll getSum(int a,int b){
  return c[b]-c[a];
}

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]+D)-X.begin();
    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+(1<<19), -INF );
  
  scanf("%lld %lld",&N,&D);
  for(int i=0;i<N;i++){
    scanf("%lld %lld",&a[i],&b[i]);
    update( i , b[i] );
    X.push_back(a[i]);
  }
  X.push_back( INF );
  for(int i=0;i<N;i++)c[i+1]=c[i]+b[i];
  P ans=solve();
  printf("%lld\n%lld\n",ans.first,ans.second);
  return 0;
}
0