-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathChain Reaction.cpp
More file actions
executable file
·64 lines (60 loc) · 1009 Bytes
/
Chain Reaction.cpp
File metadata and controls
executable file
·64 lines (60 loc) · 1009 Bytes
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;
int dp[1000001];
int main(void)
{
freopen("in.txt","r",stdin);
vector< pair<int,int> >v;
vector<int> temp;
int n;
cin>>n;
for(int i=0;i<n;++i)
{
int a,b;
cin>>a>>b;
temp.push_back(a);
v.push_back(make_pair(a,b));
}
sort(temp.begin(),temp.end());
sort(v.begin(),v.end());
dp[0]=1;
for(int i=1;i<v.size();++i)
{
int will_destroy=v[i].first-v[i].second;
if(will_destroy<1)
dp[i]=1;
else
{
int flag=0;
vector<int> ::iterator it;
it=lower_bound(temp.begin(),temp.end(),will_destroy);
if(it==temp.begin())
{
flag=1;
dp[i]=1;
}
else
{
--it;
}
if(flag==0)
{
int idx=it-temp.begin();
dp[i]=1+dp[idx];
}
}
}
temp.clear();
v.clear();
int ans=999999999;
for(int i=0;i<n;++i)
{
//cout<<dp[i]<<endl;
ans=min(ans,n-dp[i]);
}
cout<<ans;
return 0;
}