結果
| 問題 | No.1715 Dinner 2 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-10-22 23:48:15 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,509 bytes | 
| コンパイル時間 | 1,113 ms | 
| コンパイル使用メモリ | 85,872 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-09-24 07:02:01 | 
| 合計ジャッジ時間 | 2,099 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| 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[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;
}
            
            
            
        