#P1248. 加工生产调度

加工生产调度

Description

A factory has received orders for nn products. Each product must be processed in workshop A first and then in workshop B. At any moment, each workshop can process at most one product.

For product ii, its processing times in workshops A and B are AiA_i and BiB_i, respectively. Determine an order to process the nn products that minimizes the total processing time.

The total processing time is defined as the time from starting the first product until all products have finished processing in both workshops A and B.

Input Format

  • The first line contains a single integer nn, the number of products.
  • The second line contains nn integers, the processing times of the nn products in workshop A.
  • The third line contains nn integers, the processing times of the nn products in workshop B.

Output Format

  • The first line contains one integer, the minimal total processing time.
  • The second line contains one processing order that achieves the minimal total processing time. Output the product indices (from 11 to nn) separated by spaces.
5
3 5 8 7 10
6 2 1 4 9

34
1 5 4 2 3

Hint

Constraints: 1n10001 \leq n \leq 1000, 1Ai,Bi10001 \leq A_i, B_i \leq 1000.

Translated by ChatGPT 5