結果

問題 No.1715 Dinner 2
ユーザー publflpublfl
提出日時 2021-10-22 22:03:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,723 bytes
コンパイル時間 503 ms
コンパイル使用メモリ 51,040 KB
実行使用メモリ 7,184 KB
最終ジャッジ日時 2023-10-24 13:13:17
合計ジャッジ時間 1,585 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,148 KB
testcase_01 AC 3 ms
7,148 KB
testcase_02 AC 3 ms
7,148 KB
testcase_03 AC 3 ms
7,148 KB
testcase_04 AC 4 ms
7,148 KB
testcase_05 AC 3 ms
7,148 KB
testcase_06 AC 3 ms
7,148 KB
testcase_07 AC 3 ms
7,148 KB
testcase_08 AC 3 ms
7,148 KB
testcase_09 AC 3 ms
7,148 KB
testcase_10 AC 3 ms
7,148 KB
testcase_11 AC 3 ms
7,180 KB
testcase_12 AC 3 ms
7,180 KB
testcase_13 AC 4 ms
7,184 KB
testcase_14 AC 3 ms
7,180 KB
testcase_15 AC 3 ms
7,180 KB
testcase_16 AC 3 ms
7,176 KB
testcase_17 AC 4 ms
7,172 KB
testcase_18 AC 3 ms
7,148 KB
testcase_19 AC 3 ms
7,148 KB
testcase_20 AC 3 ms
7,148 KB
testcase_21 AC 3 ms
7,148 KB
testcase_22 AC 3 ms
7,148 KB
testcase_23 AC 3 ms
7,152 KB
testcase_24 AC 3 ms
7,148 KB
testcase_25 AC 3 ms
7,152 KB
testcase_26 AC 3 ms
7,152 KB
testcase_27 AC 3 ms
7,152 KB
testcase_28 AC 3 ms
7,152 KB
testcase_29 AC 4 ms
7,152 KB
testcase_30 AC 3 ms
7,152 KB
testcase_31 AC 3 ms
7,152 KB
testcase_32 AC 3 ms
7,184 KB
testcase_33 AC 3 ms
7,184 KB
testcase_34 AC 3 ms
7,184 KB
testcase_35 AC 4 ms
7,184 KB
testcase_36 AC 3 ms
7,148 KB
testcase_37 AC 3 ms
7,148 KB
testcase_38 AC 3 ms
7,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <vector>
#define MIN -1234567890

std::vector< std::pair<int,int> > V[100010];
std::pair<int,int> x[100010],y[100010];
std::pair<int,int> W[1010];

int main()
{
	
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=1;i<=a;i++)
	{
		int c,d;
		scanf("%d%d",&c,&d);
		V[c].push_back(std::make_pair(d-c,i));
		W[i] = std::make_pair(c,d);
	}
	
	std::pair<int,int> max1 = std::make_pair(MIN,0);
	std::pair<int,int> max2 = max1;
	
	for(int i=0;i<=100000;i++)
	{
		for(int j=0;j<V[i].size();j++)
		{
			if(max1.first <=V[i][j].first) max2 = max1, max1 = V[i][j];
			else if(max2.first <= V[i][j].first) max2 = V[i][j];
		}
		
		x[i] = max1, y[i] = max2;
	}
	
	
	
	long long int min = MIN, max = 0;
	long long int ans = MIN;
	while(min<=max)
	{
		long long int h = (min+max)/2;
		
		int prev = -1;
		long long int s = -h;
		for(int i=1;i<=b-2;i++)
		{
			long long int t = s<100000?s:100000;
			if(x[t].second==0)
			{
				max = h-1;
				goto u;
			}
			else if(prev==x[t].second)
			{
				if(y[t].second==0)
				{
					max = h-1;
					goto u;
				}
				else
				{
					s += (y[t].first);
					prev = y[t].second;
				}
			}
			else
			{
				s += (x[t].first);
				prev = x[t].second;
			}
		}
		
		for(int i=1;i<=a;i++)
		{
			if(i==prev) continue;
			if(s<W[i].first) continue;
			
			long long int s2 = s + (W[i].second-W[i].first);
			if(s2>100000)
			{
				ans = h;
				min = h+1;
				goto u;
			}
			else if(s2<0);
			else if(x[s2].second==0);
			else
			{
				if(x[s2].second==i)
				{
					if(y[s2].second==0);
					else
					{
						ans = h;
						min = h+1;
						goto u;
					}
				}
				else
				{
					ans = h;
					min = h+1;
					goto u;
				}
			}
		}
		max = h-1;
		u:;
	}
	printf("%lld",ans);
}
0