#abc289g. G - Shopping in AtCoder store

G - Shopping in AtCoder store

Score : 600600 points

问题描述

高桥经营着一家 AtCoder 商店。有 NN 名顾客光顾这家商店,并且店里出售 MM 件商品。第 ii 位(1iN1\leq i\leq N)顾客的购买意愿为 BiB_i,而第 jj 件(1jM1\leq j\leq M)商品的价值为 CjC_j

高桥为每件商品设定一个价格。第 ii 位顾客会购买第 jj 件商品,当且仅当其价格 PjP_j 满足以下条件:

  • Bi+CjPjB_i+C_j \geq P_j

对于每个 j=1,2,,Mj=1,2,\ldots,M,在高桥设定价格以最大化销售额的情况下,找出第 jj 件商品的总销售额。第 jj 件商品的总销售额定义为 PjP_j 与购买该商品的顾客数量的乘积。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Takahashi runs AtCoder store. NN customers visit the store, and MM items are sold in the store. The motivation of the ii-th (1iN)(1\leq i\leq N) customer is BiB _ i. The value of the jj-th (1jM)(1\leq j\leq M) item is CjC _ j.

Takahashi sets a price for each item. The ii-th customer buys one jj-th item if and only if its price PjP _ j satisfies:

  • Bi+CjPjB _ i+C _ j\geq P _ j.

For each j=1,2,,Mj=1,2,\ldots,M, find the gross sale of the jj-th item when Takahashi sets the price so that the sale is maximized. The gross sale of the jj-th item is defined as the product of PjP _ j and the number of customers that buys the jj-th item.

Constraints

  • 1N2×1051\leq N\leq2\times10^5
  • 1M2×1051\leq M\leq2\times10^5
  • 0Bi109(1iN)0\leq B _ i\leq10^9\quad(1\leq i\leq N)
  • 0Ci109(1iM)0\leq C _ i\leq10^9\quad(1\leq i\leq M)
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN MM

B1B _ 1 B2B _ 2 \ldots BNB _ N

C1C _ 1 C2C _ 2 \ldots CMC _ M

Output

Print a line containing the gross sale of the jj-th item for each j=1,2,,Mj=1,2,\ldots,M, separated by spaces.

Sample Input 1

5 4
100 200 300 400 500
120 370 470 80

Sample Output 1

1280 2350 2850 1140

For example, he may set the price of the 11-st item to 320320; then the 22-nd, 33-rd, 44-th, and 55-th customers will buy one. The gross sale of the 11-st item will be 12801280. Since he cannot make the gross sale of the 11-st item greater than 12801280, the 11-st value to be printed is 12801280.

Sample Input 2

4 4
0 2 10 2
13 13 0 4

Sample Output 2

52 52 10 18

Two customers may have the same motivation. Also, two items may have the same value.

Sample Input 3

12 15
16 592 222 983 729 338 747 61 451 815 838 281
406 319 305 519 317 590 507 946 365 5 673 478 340 176 2

Sample Output 3

6280 5466 5382 7410 5454 8120 7290 11680 5870 3670 8950 7000 5620 4608 3655

Sample Input 4

5 5
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000 1000000000

Sample Output 4

10000000000 10000000000 10000000000 10000000000 10000000000

Note that the gross sales may not fit into a 3232-bit integer type.

update @ 2024/3/10 12:05:32