洛谷 P2920 [USACO08NOV]时间管理Time Management

传送门

题目大意:

每个工作有截至时间和耗费时间,n个工作求最小开始时间。

题解:

贪心

从n-1安排,让结束时间尽量的晚。

注意:优先级

cout<<st<0?-1:st;  (X)

cout<<(st<0?-1:st);'

代码:

 

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 1090
using namespace std;

int n,st;

struct T{
    int t,s;
}w[N];

bool cmp(T a,T b){
    return a.s>b.s;
}

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d%d",&w[i].t,&w[i].s);
    sort(w+1,w+n+1,cmp);
    st=w[1].s-w[1].t;
    for(int i=2;i<=n;i++){
        int ed=min(w[i].s,st);
        st=ed-w[i].t;
    }
    //printf("%d\n",st<0?-1:st);
    cout<<(st<0?-1:st);
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/zzyh/p/7792399.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值