看了半天题解,发现:这不就是一道01背包嘛 ## 公式 f[i]
表示当前队伍1,花费i的时间的总最短时间 1
2f[j] = min(f[j], max(f[j - a[i].x], j + a[i].y)); //排在队伍1
f[j] = max(f[j], sum[i] + a[i].y - j); //排在队伍21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using namespace std;
const int N = 5e5;
struct node
{
int x, y;
bool operator<(const node &n2)
{
return y > n2.y;
}
} a[N];
int sum[N];
int f[N];
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i].x >> a[i].y;
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; ++i)
sum[i] = sum[i - 1] + a[i].x;
memset(f, 0x3f, sizeof f);
f[0] = 0;
for (int i = 1; i <= n; ++i)
{
for (int j = sum[i]; j >= 0; --j)
{
if(j >= a[i].x) f[j] = min(f[j], max(f[j - a[i].x], j + a[i].y));
f[j] = max(f[j], sum[i] + a[i].y - j);
}
for (int j = 0; j <= sum[i]; ++j)
cout << f[j] << " ";
cout << endl;
}
int ans = 1e9;
for (int j = sum[n]; ~j; --j)
{
ans = min(ans, f[j]);
}
cout << ans << endl;
}