結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー chocorusk
提出日時 2018-11-15 13:01:02
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 182 ms / 2,000 ms
コード長 1,547 bytes
コンパイル時間 1,065 ms
コンパイル使用メモリ 96,460 KB
実行使用メモリ 8,072 KB
最終ジャッジ日時 2024-12-24 13:53:38
合計ジャッジ時間 7,489 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

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