1 条题解
-
0
C++ :
#include <cstdio> #include <algorithm> using namespace std; struct J { long long t, s; }; static J j[1005]; bool cmp(const J &x, const J &y){ return x.s < y.s; } /* 1||Lmax:按截止时间升序(EDF)最优。开工时刻 t0 时第 i 个作业在 t0 + (前 i 项工时和) 完工,要求 <= 该作业的截止时间。 故 t0 <= min_i( S_i - 前 i 项工时和 )。 */ int main(){ int n; if(scanf("%d", &n) != 1) return 0; for(int i = 0; i < n; i++) scanf("%lld %lld", &j[i].t, &j[i].s); sort(j, j + n, cmp); long long pre = 0, best = -1; for(int i = 0; i < n; i++){ pre += j[i].t; long long lim = j[i].s - pre; if(i == 0 || lim < best) best = lim; } printf("%lld\n", best < 0 ? -1LL : best); return 0; }
- 1
信息
- ID
- 2583
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者