比第i个人成绩第的人数bi.第->低.
70分求助
//
// main.cpp
// P2519
//
// Created by mac on 2020/11/27.
//
#include<bits/stdc++.h>
using namespace std;
#define int long long
map<pair<int,int>,int>q;
int n;
int a[1000001];
int b[1000001];
int head[1000001];
struct cxk{
int to,nxt;
}e[1000001];
int cnt;
void add(int x,int y)
{
cnt++;
e[cnt].to=y;
e[cnt].nxt=head[x];
head[x]=cnt;
}
int f[1000001];
int ans;
signed main( )
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i]>>b[i];
if(a[i]+b[i]+1>n)
{
continue;
}
int qi=b[i]+1;
int zhong=n-a[i];
pair<int,int>qq;
qq.first=qi;
qq.second=zhong;
if(q[qq]==0)add(zhong,qi);
q[qq]++;
}
//cout<<cnt;
for(int i=1;i<=n;i++)
{
f[i]=f[i-1];
for(int j=head[i];j;j=e[j].nxt)
{
int to=e[j].to;
pair<int,int>qq;
qq.first=to;
qq.second=i;
f[i]=max(f[i],f[to-1]+q[qq]);
}
}
//cout<<f[3];
ans=n-f[n];
//cout<<f[n]<<endl;
cout<<ans;
}