[LUOGU] P2920 [USACO08NOV]时间管理Time Management
#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; }
本文来自博客园,作者:GhostCai,转载请注明原文链接:https://www.cnblogs.com/ghostcai/p/9260604.html