33OJ
登录 注册

#P17546. [JAG 2026 Summer Camp #2] Vibe Coding

    ID: 20272 远端评测题 3000ms 2048MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>动态规划 DP平衡树背包 DP动态规划优化ICPC2026

[JAG 2026 Summer Camp #2] Vibe Coding

Problem Description

Shobon has decided to use a generative AI to help develop a software project. The project consists of NN tasks. Each task ii (i=1,2,…,Ni=1,2,\ldots,N) has a predetermined implementation workload AiA_i and complexity BiB_i.

Shobon can proceed with these tasks in any order. However, he cannot work on more than one task at the same time.

Each task ii (i=1,2,…,Ni=1,2,\ldots,N) can be completed in one of the following two ways:

  • Implement the task manually. Shobon writes the code himself, which takes AiA_i units of time.
  • Use the generative AI. To make the AI generate correct code, Shobon explains the current task and all previously completed tasks to the AI. Let SS be the sum of the complexities of all previously completed tasks. Preparing this explanation takes S+BiS+B_i units of time. The AI then finishes the implementation instantly, so no additional implementation time is required. Thus, completing this task by using the AI takes a total of S+BiS+B_i units of time.

Regardless of which method is used, once task ii is completed, its complexity BiB_i is included in future values of SS when using the generative AI.

Find the minimum total time required to complete all tasks.

Input Format

The input consists of three lines in the following format.

N
A_1 A_2 ... A_N
B_1 B_2 ... B_N

In the first line, the number of tasks, NN, is given (1≤N≤2×1051\le N\le 2\times 10^5). The second line contains NN integers, A1,A2,…,ANA_1,A_2,\ldots,A_N, each between 11 and 10910^9, inclusive, representing the implementation workloads of the NN tasks. The third line contains NN integers, B1,B2,…,BNB_1,B_2,\ldots,B_N, each between 11 and 10810^8, inclusive, representing the complexities of the NN tasks.

Output Format

Output in a line the minimum total time required to complete all tasks.

3
10 6 10
5 2 4
18
1
4
10
4
5
100 100 100 100 100
5 1 4 2 3
35
12
18 7 25 12 30 5 16 22 9 28 14 20
6 11 2 8 1 13 5 3 10 4 9 7
118

Hint

For Sample Input 1, consider using the generative AI for tasks 22 and 33 in this order, and then implementing task 11 manually.

  • When task 22 is started, no task has been completed yet. This task takes 0+B2=20+B_2=2 units of time.
  • When task 33 is started, task 22 has been completed. This task takes B2+B3=2+4=6B_2+B_3=2+4=6 units of time.
  • Finally, implementing task 11 manually takes A1=10A_1=10 units of time.

Thus, all tasks can be completed in 2+6+10=182+6+10=18 units of time, which is the minimum possible.