結果

問題 No.1715 Dinner 2
ユーザー kotatsugamekotatsugame
提出日時 2021-10-22 23:48:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,509 bytes
コンパイル時間 1,914 ms
コンパイル使用メモリ 84,288 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-24 16:07:06
合計ジャッジ時間 2,891 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 7 ms
4,348 KB
testcase_12 AC 8 ms
4,348 KB
testcase_13 AC 8 ms
4,348 KB
testcase_14 AC 6 ms
4,348 KB
testcase_15 AC 8 ms
4,348 KB
testcase_16 AC 6 ms
4,348 KB
testcase_17 AC 5 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 3 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 9 ms
4,348 KB
testcase_33 AC 8 ms
4,348 KB
testcase_34 AC 9 ms
4,348 KB
testcase_35 AC 10 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    7 | main()
      | ^~~~

ソースコード

diff #

#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[2]={true,true};
		int now[2]={0,0},id[2]={0,0};
		multiset<pair<int,int> >S[2];
		int prv[2]={-1,-1};
		for(int d=0;d<D;d++)
		{
			for(int i=0;i<2;i++)if(ok[i])
			{
				while(id[i]<N&&PQ[id[i]].first<=now[i]-mid)
				{
					S[i].insert(PQ[id[i]++].second);
				}
				while(id[i]>0&&PQ[id[i]-1].first>now[i]-mid)
				{
					S[i].erase(S[i].find(PQ[--id[i]].second));
				}
			}
			if(d==0)
			{
				auto it=S[0].begin();
				if(it==S[0].end())
				{
					ok[0]=ok[1]=false;
				}
				else
				{
					now[0]-=it->first;
					prv[0]=it->second;
					it++;
					if(it==S[0].end())
					{
						ok[1]=false;
					}
					else
					{
						now[1]-=it->first;
						prv[1]=it->second;
					}
				}
			}
			else
			{
				for(int i=0;i<2;i++)if(ok[i])
				{
					if(S[i].empty())
					{
						ok[i]=false;
						continue;
					}
					auto it=S[i].begin();
					if(it->second!=prv[i])
					{
						now[i]-=it->first;
						prv[i]=it->second;
					}
					else
					{
						it++;
						if(it!=S[i].end())
						{
							now[i]-=it->first;
							prv[i]=it->second;
						}
						else ok[i]=false;
					}
				}
			}
		}
		if(ok[0]||ok[1])L=mid;
		else R=mid;
	}
	cout<<L<<endl;
}
0