Submission #1135575

#TimeUsernameProblemLanguageResultExecution timeMemory
1135575yellowtoadAdvertisement 2 (JOI23_ho_t2)C++20
10 / 100
311 ms41312 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#define f first
#define s second
#define int long long
using namespace std;

int n, suf[500010], ans = 1e9;
pair<int,int> a[500010], b[500010];
vector<int> v;
vector<pair<int,int>> aa, bb;

signed main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i].f >> a[i].s;
		b[i] = a[i];
		a[i].s -= a[i].f;
		b[i].s += b[i].f;
	}
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	for (int i = 1; i <= n; i++) if (a[i].f != a[i+1].f) aa.push_back(a[i]), bb.push_back(b[i]);
	for (int i = bb.size()-1; i >= 0; i--) {
		while ((v.size()) && (v.back() <= bb[i].s)) v.pop_back();
		v.push_back(bb[i].s);
		suf[i] = v.size();
	}
	v.clear();
	ans = suf[0];
	for (int i = 0; i < aa.size(); i++) {
		while ((v.size()) && (v.back() <= aa[i].s)) v.pop_back();
		v.push_back(aa[i].s);
		ans = min(ans,(int)v.size()+suf[i]-1);
	}
	cout << ans << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...