#P2672. [NOIP 2015 普及组] 推销员

    ID: 1696 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>贪心2015线段树树状数组NOIp 普及组

[NOIP 2015 普及组] 推销员

Description

A Ming is a salesman. He is assigned to promote his company’s products on Screw Street. Screw Street is a dead-end; the exit and entrance are the same. One side of the street is a wall, and the other side has households. There are NN households on Screw Street, and the ii-th household is SiS_i meters from the entrance. Because multiple households can live in the same building, several households may be at the same distance from the entrance. A Ming will enter from the entrance, promote products to XX households on Screw Street one by one, and then walk back along the same route.

For every 11 meter he walks, he accumulates 11 fatigue point. Promoting to the ii-th household accumulates AiA_i fatigue points. A Ming is a workaholic. He wants to know, for different values of XX, under the premise of not walking any extra distance, what is the maximum total fatigue he can accumulate.

Input Format

The first line contains a positive integer NN, the number of households on Screw Street.

The next line contains NN non-negative integers; the ii-th integer SiS_i is the distance from the ii-th household to the entrance. It is guaranteed that S1S2Sn<108S_1 \le S_2 \le \cdots \le S_n <10^8.

The next line contains NN positive integers; the ii-th integer AiA_i is the fatigue accumulated by promoting to the ii-th household. It is guaranteed that Ai<1000A_i<1000.

Output Format

Output NN lines, each with one positive integer. The integer on the ii-th line denotes the maximum total fatigue when X=iX=i.

5
1 2 3 4 5
1 2 3 4 5
15
19
22
24
25
5
1 2 2 4 5
5 4 3 4 1
12
17
21
24
27

Hint

Explanation for Sample 1:

X=1X=1: promote to household 55. The round-trip walking fatigue is 5+55+5, the promotion fatigue is 55, and the total fatigue is 1515.

X=2X=2: promote to households 4,54,5. The round-trip walking fatigue is 5+55+5, the promotion fatigue is 4+54+5, and the total fatigue is 5+5+4+5=195+5+4+5=19.

X=3X=3: promote to households 3,4,53,4,5. The round-trip walking fatigue is 5+55+5, the promotion fatigue is 3+4+53+4+5, and the total fatigue is 5+5+3+4+5=225+5+3+4+5=22.

X=4X=4: promote to households 2,3,4,52,3,4,5. The round-trip walking fatigue is 5+55+5, the promotion fatigue is 2+3+4+52+3+4+5, and the total fatigue is 5+5+2+3+4+5=245+5+2+3+4+5=24.

X=5X=5: promote to households 1,2,3,4,51,2,3,4,5. The round-trip walking fatigue is 5+55+5, the promotion fatigue is 1+2+3+4+51+2+3+4+5, and the total fatigue is 5+5+1+2+3+4+5=255+5+1+2+3+4+5=25.

Explanation for Sample 2:

X=1X=1: promote to household 44. The round-trip walking fatigue is 4+44+4, the promotion fatigue is 44, and the total fatigue is 4+4+4=124+4+4=12.

X=2X=2: promote to households 1,41,4. The round-trip walking fatigue is 4+44+4, the promotion fatigue is 5+45+4, and the total fatigue is 4+4+5+4=174+4+5+4=17.

X=3X=3: promote to households 1,2,41,2,4. The round-trip walking fatigue is 4+44+4, the promotion fatigue is 5+4+45+4+4, and the total fatigue is 4+4+5+4+4=214+4+5+4+4=21.

X=4X=4: promote to households 1,2,3,41,2,3,4. The round-trip walking fatigue is 4+44+4, the promotion fatigue is 5+4+3+45+4+3+4, and the total fatigue is 4+4+5+4+3+4=244+4+5+4+3+4=24. Or promote to households 1,2,4,51,2,4,5. The round-trip walking fatigue is 5+55+5, the promotion fatigue is 5+4+4+15+4+4+1, and the total fatigue is 5+5+5+4+4+1=245+5+5+4+4+1=24.

X=5X=5: promote to households 1,2,3,4,51,2,3,4,5. The round-trip walking fatigue is 5+55+5, the promotion fatigue is 5+4+3+4+15+4+3+4+1, and the total fatigue is 5+5+5+4+3+4+1=275+5+5+4+3+4+1=27.

Constraints:

For 20%20\% of the testdata, 1N201 \le N \le 20. For 40%40\% of the testdata, 1N1001 \le N \le 100. For 60%60\% of the testdata, 1N10001 \le N \le 1000. For 100%100\% of the testdata, 1N1000001 \le N \le 100000.

Translated by ChatGPT 5