結果
問題 |
No.1715 Dinner 2
|
ユーザー |
|
提出日時 | 2021-10-22 23:40:49 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,565 bytes |
コンパイル時間 | 1,029 ms |
コンパイル使用メモリ | 85,904 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-24 06:35:12 |
合計ジャッジ時間 | 2,232 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 36 WA * 2 |
コンパイルメッセージ
main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 7 | main() | ^~~~
ソースコード
#include<iostream> #include<set> #include<vector> #include<algorithm> using namespace std; int N,D; main() { cin>>N>>D; vector<pair<int,pair<int,int> > >PQ(N); for(int i=0;i<N;i++) { int p,q;cin>>p>>q; PQ[i]=make_pair(p,make_pair(p-q,i)); } sort(PQ.begin(),PQ.end()); int L=-1e9,R=1; while(R-L>1) { int mid=(L+R)/2; bool ok=true; { int now=0; int id=0; multiset<pair<int,int> >S; int prv=-1; for(int d=0;d<D;d++) { while(id<N&&PQ[id].first<=now-mid) { S.insert(PQ[id].second); id++; } while(id>0&&PQ[id-1].first>now-mid) { id--; S.erase(S.find(PQ[id].second)); } if(S.empty()) { ok=false; break; } auto it=S.begin(); if(it->second!=prv) { now-=it->first; prv=it->second; } else { it++; if(it==S.end()) { ok=false; break; } now-=it->first; prv=it->second; } } } if(ok)L=mid; else { ok=true; int now=0; int id=0; multiset<pair<int,int> >S; int prv=-1; for(int d=0;d<D;d++) { while(id<N&&PQ[id].first<=now-mid) { S.insert(PQ[id].second); id++; } while(id>0&&PQ[id-1].first>now-mid) { id--; S.erase(S.find(PQ[id].second)); } if(S.empty()) { ok=false; break; } auto it=S.begin(); if(prv!=-1&&it->second!=prv) { now-=it->first; prv=it->second; } else { it++; if(it==S.end()) { ok=false; break; } now-=it->first; prv=it->second; } } if(ok)L=mid; else R=mid; } } cout<<L<<endl; }