-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path607a.cpp
50 lines (44 loc) · 1.13 KB
/
607a.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
using p = pair<int, int>;
const int MAX = 1000000;
vector<p> arr;
int dp[MAX+1];
inline void quick_IO(){
ios_base :: sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
bool comp(const p& a, const p& b){
return a.first < b.first;
}
int main(){
quick_IO();
int n;
cin>>n;
arr.resize(n);
int i;
int position, power;
for(i=0;i<n;i++) {
cin>>position>>power;
arr[i] = p(position, power);
}
sort(arr.begin(), arr.end(), comp);
// for(i=0;i<n;i++) cout<<arr[i].first<<" "<<arr[i].second<<endl;
dp[0] = 1;
for(i=1;i<n;i++){
auto it = lower_bound(arr.begin(), arr.begin()+i, p(arr[i].first-arr[i].second, 0), comp);
int num = distance(it, arr.begin()+i);
dp[i] = dp[i - (num + 1)] + 1;
}
// for(i=0;i<n;i++) cout<<dp[i]<<" ";
cout<<n-*max_element(dp, dp+n)<<"\n";
return 0;
}
// 첫 제출은 sort안하고 upper bound를 사용해서 틀렸음.
// sort 해야함.
// pair에서 upper bound 사용하는 법