见7.3测试

#include<iostream>
#include<algorithm>
#include<cstdio>

using namespace std; 

const int MAXN=100005;

inline int rd(){
    int ret=0,f=1;char c;
    while(c=getchar(),!isdigit(c))f=c=='-'?-1:1;
    while(isdigit(c))ret=ret*10+c-'0',c=getchar();
    return ret*f;
}

struct Node{
    int lon,tim;
}nodes[MAXN];
bool cmp(const Node &x,const Node &y){
    return x.tim<y.tim;
}

int n;

int main(){
//    freopen("manage.in","r",stdin);
//    freopen("manage.out","w",stdout);
    n=rd();
    for(int i=1;i<=n;i++){
        nodes[i].lon = rd();
        nodes[i].tim = rd();
    }
    sort(nodes+1,nodes+1+n,cmp);
    long long sum=0,mn=(1<<29),v;
    for(int i=1;i<=n;i++){
        sum+=nodes[i].lon;
        v=nodes[i].tim-sum;
        if(v<0) return puts("-1"),0;
        mn=min(mn,v);
    }
    printf("%lld",mn);
    return 0;
}
 

 

相关文章:

  • 2021-12-20
  • 2021-06-29
  • 2021-07-17
  • 2021-09-11
  • 2022-01-07
  • 2021-07-15
  • 2021-10-15
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-09
  • 2022-12-23
  • 2021-12-03
  • 2022-12-23
  • 2022-02-07
相关资源
相似解决方案