結果
問題 |
No.448 ゆきこーだーの雨と雪 (3)
|
ユーザー |
![]() |
提出日時 | 2016-11-18 23:30:59 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,293 bytes |
コンパイル時間 | 1,204 ms |
コンパイル使用メモリ | 163,236 KB |
実行使用メモリ | 7,628 KB |
最終ジャッジ日時 | 2024-11-26 08:39:13 |
合計ジャッジ時間 | 6,483 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 WA * 4 RE * 15 |
コンパイルメッセージ
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,&D); | ~~~~~^~~~~~~~~~~~~~~~~~~ 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]); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#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); int tree[500]; ll getMax(int l,int r){ int res=- (1e9+1); 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, (int)(b[i]) ); i++; } } return res; } void update(int i,int x){ tree[i/500]=max(tree[i/500],x); } 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+500, -(1e9+7) ); 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; }