这个题其实不难,就是按照结束时候的顺序从大到小走一遍,能送的就送,如果区间不重合就更新一下
代码:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<time.h>
using namespace std;
typedef long long ll;
ll read(){
int ans=;
char last=' ',ch=getchar();
while(ch<'' || ch>'')last=ch,ch=getchar();
while(ch>='' && ch<='')ans=ans*+ch-'',ch=getchar();
if(last=='-')ans=-ans;
return ans;
} const int N=1e6+; //ll a[N],b[N],c[N],n,m,ans;
//ll sum; ll t,n; struct qwq
{
ll a,b;
}num[N]; bool cmp(qwq x,qwq y)
{
return x.b>y.b;
} int main()
{ n=read();
for(int i=;i<=n;i++)
{
num[i].a=read();
num[i].b=read(); }
sort(num+,num++n,cmp);
t=num[].b;
for(int i=;i<=n;i++)
{
if(t>num[i].b)t=num[i].b;
t-=num[i].a;
} cout<<t;
}