結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー dohatsutsudohatsutsu
提出日時 2016-11-18 23:47:15
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,275 bytes
コンパイル時間 1,389 ms
コンパイル使用メモリ 163,044 KB
実行使用メモリ 13,016 KB
最終ジャッジ日時 2024-05-04 18:59:35
合計ジャッジ時間 6,422 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,784 KB
testcase_01 AC 4 ms
6,784 KB
testcase_02 AC 3 ms
6,912 KB
testcase_03 AC 4 ms
6,912 KB
testcase_04 AC 4 ms
6,912 KB
testcase_05 AC 4 ms
6,912 KB
testcase_06 AC 4 ms
6,784 KB
testcase_07 AC 4 ms
6,784 KB
testcase_08 WA -
testcase_09 AC 4 ms
6,912 KB
testcase_10 AC 4 ms
6,784 KB
testcase_11 AC 4 ms
6,912 KB
testcase_12 WA -
testcase_13 AC 29 ms
7,552 KB
testcase_14 AC 35 ms
7,772 KB
testcase_15 AC 88 ms
9,176 KB
testcase_16 WA -
testcase_17 AC 155 ms
11,224 KB
testcase_18 AC 25 ms
7,680 KB
testcase_19 WA -
testcase_20 AC 69 ms
8,660 KB
testcase_21 AC 208 ms
12,248 KB
testcase_22 AC 68 ms
8,664 KB
testcase_23 AC 188 ms
12,372 KB
testcase_24 WA -
testcase_25 AC 202 ms
12,252 KB
testcase_26 WA -
testcase_27 AC 136 ms
10,840 KB
testcase_28 WA -
testcase_29 AC 72 ms
8,796 KB
testcase_30 WA -
testcase_31 AC 27 ms
7,672 KB
testcase_32 AC 33 ms
7,628 KB
testcase_33 WA -
testcase_34 AC 263 ms
12,876 KB
testcase_35 WA -
testcase_36 AC 308 ms
13,012 KB
testcase_37 WA -
testcase_38 AC 245 ms
12,760 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:60:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   60 |   scanf("%lld %lld",&N,&K);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~
main.cpp:62:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   62 |     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){
  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();
    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]);
  }
  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