Blog of RuSun

\begin {array}{c} \mathfrak {One Problem Is Difficult} \\\\ \mathfrak {Because You Don't Know} \\\\ \mathfrak {Why It Is Diffucult} \end {array}

P1248 加工生产调度

P1248 加工生产调度

查看代码
1
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
45
46
47
48
#include <cstdio>
#include <algorithm>
using namespace std;
template <class Type>
void read(Type &x)
{
char c;
bool flag = false;
while ((c = getchar()) < '0' || c > '9')
c == '-' && (flag = true);
x = c - '0';
while ((c = getchar()) >= '0' && c <= '9')
x = (x << 3) + (x << 1) + c - '0';
if (flag) x = ~x + 1;
}
template <class Type, class ...rest>
void read(Type &x, rest &...y) { read(x), read(y...); }
template <class Type>
void write(Type x)
{
if (x < 0) putchar('-'), x = ~x + 1;
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
const int N = 1e3 + 10;
int n, w[N], v[N], p[N], q[N];
int main ()
{
read(n);
for (int i = 1; i <= n; ++i) read(w[i]);
for (int i = 1; i <= n; ++i) read(v[i]);
for (int i = 1; i <= n; ++i) p[i] = i;
sort(p + 1, p + n + 1, [&](int a, int b) { return min(w[a], v[a]) < min(w[b], v[b]); } );
for (int i = 1, l = 1, r = n; i <= n; ++i)
if (w[p[i]] < v[p[i]]) q[l++] = p[i];
else q[r--] = p[i];
int l = 0, r = 0;
for (int i = 1; i <= n; ++i)
{
l += w[q[i]];
if (r < l) r = l;
r += v[q[i]];
}
write(r), puts("");
for (int i = 1; i <= n; ++i)
write(q[i]), putchar(' ');
return 0;
}