結果

問題 No.2573 moving up
ユーザー MagentorMagentor
提出日時 2023-12-06 12:19:11
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 995 bytes
コンパイル時間 3,025 ms
コンパイル使用メモリ 253,292 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-06 12:19:16
合計ジャッジ時間 4,430 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 3 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 RE -
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 RE -
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
int main(){
	int H,W;
	cin>>H>>W;
	int base=0;
	priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> ap,dap;
	vector<int> Y(W);
	for(int i=0;i<W;i++){
		int x,y;
		cin>>x>>y;
		base+=x-1;
		ap.push({max(1,y-(x-1)),i});
		Y[i]=y;
		//cout<<max(1,y-(x-1))<<" "<<min(W+1,Y[i]+1)<<endl;
	}
	
	int rej=0,now=0;
	int extra=0;
	vector<int> seen(W,0);
	for(int i=1;i<=W;i++){
		while(ap.size() and ap.top().first==i){
			int idx=ap.top().second;
			ap.pop();
			seen[idx]++;
			now++;
			dap.push({min(W+1,Y[idx]+1),idx});
		}
		while(dap.size() and dap.top().first==i){
			int idx=dap.top().second;
			dap.pop();
			if(seen[idx]<2){
				now--;
				seen[idx]++;
				rej++;
			}
		}
		if(0<rej){
			extra+=(rej--);
		}
		else if(0<now){
			int idx=dap.top().second;
			now--;
			seen[idx]=2;
			dap.pop();
		}
		else{
			int idx=ap.top().first;
			extra+=ap.top().first - i;
			seen[idx]=2;
			ap.pop();
		}
	}
	cout<<base+extra<<"\n";
}
0