結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー chocoruskchocorusk
提出日時 2018-11-15 13:01:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 1,547 bytes
コンパイル時間 722 ms
コンパイル使用メモリ 94,352 KB
実行使用メモリ 7,804 KB
最終ジャッジ日時 2023-08-26 01:14:48
合計ジャッジ時間 4,927 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,396 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
5,604 KB
testcase_03 AC 2 ms
5,456 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
5,404 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
5,404 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 21 ms
5,652 KB
testcase_14 AC 22 ms
5,912 KB
testcase_15 AC 54 ms
5,676 KB
testcase_16 AC 93 ms
5,908 KB
testcase_17 AC 94 ms
4,612 KB
testcase_18 AC 16 ms
5,676 KB
testcase_19 AC 132 ms
6,808 KB
testcase_20 AC 45 ms
4,376 KB
testcase_21 AC 121 ms
5,260 KB
testcase_22 AC 49 ms
4,528 KB
testcase_23 AC 124 ms
5,876 KB
testcase_24 AC 31 ms
4,384 KB
testcase_25 AC 125 ms
5,448 KB
testcase_26 AC 15 ms
4,380 KB
testcase_27 AC 92 ms
5,204 KB
testcase_28 AC 89 ms
5,880 KB
testcase_29 AC 51 ms
4,652 KB
testcase_30 AC 138 ms
6,780 KB
testcase_31 AC 19 ms
5,576 KB
testcase_32 AC 21 ms
5,568 KB
testcase_33 AC 142 ms
7,104 KB
testcase_34 AC 135 ms
5,764 KB
testcase_35 AC 143 ms
7,804 KB
testcase_36 AC 130 ms
6,192 KB
testcase_37 AC 144 ms
6,704 KB
testcase_38 AC 132 ms
5,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n, k;
	cin>>n>>k;
	int t[200000], d[200000];
	ll sum0=0;
	for(int i=0; i<n; i++){
		cin>>t[i]>>d[i];
		sum0+=d[i];
	}
	int d1=0, d2=1e9;
	while(d1!=d2){
		int dmid=(d1+d2)/2;
		int pr=-k;
		bool nuee=0;
		for(int i=0; i<n; i++){
			if(d[i]>dmid){
				if(t[i]-pr<k){
					nuee=1;
					break;
				}
				pr=t[i];
			}
		}
		if(nuee) d1=dmid+1;
		else d2=dmid;
	}
	cout<<d1<<endl;
	if(d1==0){
		cout<<0<<endl;
		return 0;
	}
	vector<int> v;
	ll sum1=0;
	for(int i=0; i<n; i++){
		if(d[i]>d1){
			v.push_back(t[i]);
			sum1+=d[i];
		}
	}
	vector<int> ind;
	vector<int> tv;
	for(int i=0; i<n; i++){
		int i0=lower_bound(v.begin(), v.end(), t[i])-v.begin();
		bool muri=0;
		if(i0<v.size()){
			if(abs(t[i]-v[i0])<k) muri=1;
		}
		if(i0-1>=0){
			if(abs(t[i]-v[i0-1])<k) muri=1;
		}
		if(!muri){
			ind.push_back(i);
			tv.push_back(t[i]);
		}
	}
	ll dp[200001], mx[200001];
	dp[0]=0, mx[0]=0;
	for(int j=0; j<ind.size(); j++){
		dp[j+1]=d[ind[j]];
		int j1=upper_bound(tv.begin(), tv.end(), tv[j]-k)-tv.begin();
		if(j1==0){
			mx[j+1]=max(mx[j], dp[j+1]);
			continue;
		}
		dp[j+1]+=mx[j1];
		mx[j+1]=max(mx[j], dp[j+1]);
	}
	cout<<sum0-(mx[ind.size()]+sum1)<<endl;
	return 0;
}
0