Shop scheduling problem:
For each item of three ways:
- A used time <B elapsed time. Called a class
- A used time> B elapsed time. Referred to as second-class
- And A, B equal to three cases. Called three
The problem into it, there is a class B is occupying time increases, the second category B is occupied with less time.
B is certainly the first change after more than fewer, to make time to spend a minimum.
Then consider the internal processing sequence in each case.
Equal without regard. No effect on the order.
First, the product is a waste of time to start the first time in A, we want to reduce it, so that a small to large.
Then when the last time wasted is time remaining in B, A, and more than that, so make large B in B in the process of first ran, ran the last little progress.
After consideration of the processing sequence can direct simulation.
#include <bits/stdc++.h>
#define N 100103
using namespace std;
int n, ans, delta;
struct product {
int a, b, belong, id;
}data[N];
bool cmp(product s, product b)
{
if (s.belong != b.belong)
return s.belong < b.belong;
if (s.belong == 3)
return s.b > b.b;
if (s.belong == 1) // 先开始的a一定要最小
return s.a < b.a;
}
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &data[i].a), data[i].id = i;
for (int i = 1; i <= n; i++)
scanf("%d", &data[i].b);
for (int i = 1; i <= n; i++)//分类
{
if (data[i].a == data[i].b);
data[i].belong = 2;
if (data[i].a < data[i].b)//先让b的时间长一些
data[i].belong = 1;
if (data[i].a > data[i].b)
data[i].belong = 3;
}
sort(data + 1, data + 1 + n, cmp);
for (int i = 1; i <= n; i++)//delta是指B中时间和A中时间差
{
ans += data[i].a;
delta -= data[i].a;
delta = max(delta, 0);
delta += data[i].b;
}
ans += delta;
printf("%d\n", ans);
for (int i = 1; i <= n; i++)
printf("%d ", data[i].id);
return 0;
}