传送门

题目大意:

每个工作有截至时间和耗费时间,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

相关文章:

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