結果
| 問題 |
No.1715 Dinner 2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-10-22 23:26:14 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 952 bytes |
| コンパイル時間 | 930 ms |
| コンパイル使用メモリ | 85,240 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-23 07:57:38 |
| 合計ジャッジ時間 | 1,977 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 35 WA * 3 |
コンパイルメッセージ
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;
int now=0;
int id=0;
multiset<pair<int,int> >S;
int prv=-1;
bool ok=true;
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 R=mid;
}
cout<<L<<endl;
}