結果
問題 | No.448 ゆきこーだーの雨と雪 (3) |
ユーザー | dohatsutsu |
提出日時 | 2016-11-19 00:14:46 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 365 ms / 2,000 ms |
コード長 | 1,561 bytes |
コンパイル時間 | 1,254 ms |
コンパイル使用メモリ | 148,172 KB |
実行使用メモリ | 11,244 KB |
最終ジャッジ日時 | 2023-09-02 12:52:57 |
合計ジャッジ時間 | 7,563 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
9,212 KB |
testcase_01 | AC | 3 ms
9,272 KB |
testcase_02 | AC | 3 ms
9,140 KB |
testcase_03 | AC | 3 ms
9,212 KB |
testcase_04 | AC | 4 ms
9,288 KB |
testcase_05 | AC | 3 ms
9,348 KB |
testcase_06 | AC | 3 ms
9,276 KB |
testcase_07 | AC | 3 ms
9,160 KB |
testcase_08 | AC | 3 ms
9,232 KB |
testcase_09 | AC | 3 ms
9,252 KB |
testcase_10 | AC | 4 ms
9,344 KB |
testcase_11 | AC | 4 ms
9,276 KB |
testcase_12 | AC | 3 ms
9,252 KB |
testcase_13 | AC | 43 ms
9,544 KB |
testcase_14 | AC | 55 ms
9,516 KB |
testcase_15 | AC | 116 ms
10,232 KB |
testcase_16 | AC | 226 ms
10,472 KB |
testcase_17 | AC | 152 ms
10,592 KB |
testcase_18 | AC | 25 ms
9,636 KB |
testcase_19 | AC | 317 ms
10,968 KB |
testcase_20 | AC | 89 ms
9,896 KB |
testcase_21 | AC | 254 ms
10,980 KB |
testcase_22 | AC | 89 ms
9,804 KB |
testcase_23 | AC | 252 ms
10,840 KB |
testcase_24 | AC | 75 ms
9,676 KB |
testcase_25 | AC | 295 ms
10,924 KB |
testcase_26 | AC | 36 ms
9,492 KB |
testcase_27 | AC | 181 ms
10,320 KB |
testcase_28 | AC | 216 ms
10,484 KB |
testcase_29 | AC | 104 ms
9,924 KB |
testcase_30 | AC | 308 ms
10,924 KB |
testcase_31 | AC | 32 ms
9,472 KB |
testcase_32 | AC | 18 ms
9,596 KB |
testcase_33 | AC | 326 ms
11,240 KB |
testcase_34 | AC | 298 ms
11,244 KB |
testcase_35 | AC | 365 ms
11,184 KB |
testcase_36 | AC | 168 ms
11,132 KB |
testcase_37 | AC | 325 ms
11,196 KB |
testcase_38 | AC | 214 ms
11,116 KB |
ソースコード
#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,mid; while(left<right){ mid=(left+right)/2; if(check(mid))right=mid; else left=mid+1; } printf("%lld\n",left); printf("%lld\n",solve(left)); return 0; }