这个题其实不难,就是按照结束时候的顺序从大到小走一遍,能送的就送,如果区间不重合就更新一下
代码:
#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=0; char last=‘ ‘,ch=getchar(); while(ch<‘0‘ || ch>‘9‘)last=ch,ch=getchar(); while(ch>=‘0‘ && ch<=‘9‘)ans=ans*10+ch-‘0‘,ch=getchar(); if(last==‘-‘)ans=-ans; return ans; } const int N=1e6+5; //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=1;i<=n;i++) { num[i].a=read(); num[i].b=read(); } sort(num+1,num+1+n,cmp); t=num[1].b; for(int i=1;i<=n;i++) { if(t>num[i].b)t=num[i].b; t-=num[i].a; } cout<<t; }
原文:https://www.cnblogs.com/lcezych/p/10939838.html