题面
Sol
首先显然吃饭久的要排在前面
之后再来分配队伍,设\(f[i][j]\)表示到第\(i\)个人,\(A\)队伍要等\(j\)的最小吃完饭时间
那么就是一个简单的背包吧。。。
# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
# define Sqr(x) ((x) * (x))
using namespace std;
typedef long long ll;
const int _(205);
IL ll Read(){
RG ll x = 0, z = 1; RG char c = getchar();
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x * z;
}
int n, a[_], b[_], sum[_], f[_][_ * _], ans = 2e9, id[_];
IL bool Cmp(RG int x, RG int y){ return b[x] > b[y]; }
int main(RG int argc, RG char* argv[]){
n = Read();
for(RG int i = 1; i <= n; ++i) a[i] = Read(), b[i] = Read(), id[i] = i;
sort(id + 1, id + n + 1, Cmp);
for(RG int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + a[id[i]];
Fill(f, 63); f[0][0] = 0;
for(RG int i = 1; i <= n; ++i)
for(RG int j = 0; j <= sum[i]; ++j){
f[i][j] = max(f[i - 1][j], (sum[i] - j) + b[id[i]]);
if(j >= a[id[i]]) f[i][j] = min(f[i][j], max(f[i - 1][j - a[id[i]]], j + b[id[i]]));
}
for(RG int i = 0; i <= sum[n]; ++i) ans = min(ans, f[n][i]);
printf("%d\n", ans);
return 0;
}
原文地址:https://www.cnblogs.com/cjoieryl/p/8318872.html
时间: 2024-10-20 05:47:06