[LUOGU] P2920 [USACO08NOV]时间管理Time Management

见7.3测试

#include<iostream>
#include<algorithm>
#include<cstdio> using namespace std; const int MAXN=; inline int rd(){
int ret=,f=;char c;
while(c=getchar(),!isdigit(c))f=c=='-'?-:;
while(isdigit(c))ret=ret*+c-'',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=;i<=n;i++){
nodes[i].lon = rd();
nodes[i].tim = rd();
}
sort(nodes+,nodes++n,cmp);
long long sum=,mn=(<<),v;
for(int i=;i<=n;i++){
sum+=nodes[i].lon;
v=nodes[i].tim-sum;
if(v<) return puts("-1"),;
mn=min(mn,v);
}
printf("%lld",mn);
return ;
}
上一篇:题解 P2920 【[USACO08NOV]时间管理Time Management】


下一篇:使用Compose和Machine来Docker化Flask:从本地到云端