CF1793E.Velepin and Marketing

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The famous writer Velepin is very productive. Recently, he signed a contract with a well-known publication and now he needs to write kik_i books for ii-th year. This is not a problem for him at all, he can write as much as he wants about samurai, space, emptiness, insects and werewolves.

He has nn regular readers, each of whom in the ii-th year will read one of the kik_i books published by Velepin. Readers are very fond of discussing books, so the jj-th of them will be satisfied within a year if at least aja_j persons read the same book as him (including himself).

Velepin has obvious problems with marketing, so he turned to you! A well-known book reading service can control what each of Velepin's regular readers will read, but he does not want books to be wasted, so someone should read each book. And so they turned to you with a request to tell you what the maximum number of regular readers can be made satisfied during each of the years, if you can choose each person the book he will read.

著名作家维莱平非常高产。最近,他与一家知名出版机构签订了一份合同,现在他需要在第 ii 年完成 kik_i 本书的写作。这对他而言完全不是问题——他可以随心所欲地创作关于武士、太空、虚空、昆虫以及狼人的作品。

他有 nn 位固定读者,每位读者在第 ii 年会从维莱平当年出版的 kik_i 本书中选择一本阅读。读者们非常热衷于讨论书籍,因此第 jj 位读者在某一年内感到满意,当且仅当至少有 aja_j 人(包括他自己)阅读了与他相同的那本书。

维莱平在市场营销方面存在明显短板,于是他向你求助!一家知名的图书阅读服务平台能够控制每位固定读者所阅读的具体书籍;但维莱平不希望任何一本书被浪费,因此每本书都必须至少被一人阅读。于是他们请求你:在满足“每本书至少被一人阅读”的前提下,通过为每位读者指定其所读的书,求出每年最多能让多少位固定读者感到满意。

输入格式

The first line contains a single integer nn (2≤n≤3⋅105)(2 \le n \le 3 \cdot 10^5) — the number of regular readers of Velepin.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤n)(1 \le a_i \le n) — the number of necessary readers of the same book for the happiness of the ii-th person.

The third line contains a single integer qq (1≤q≤3⋅105)(1 \le q \le 3 \cdot 10^5) — the number of years to analyze.

Each of the following qq lines contains a single integer kjk_j (2≤kj≤n)(2 \le k_j \le n) — the number of books that Velepin must write in jj-th a year.

第一行包含一个整数 nn(2≤n≤3⋅1052 \le n \le 3 \cdot 10^5)—— Velepin 的常规读者人数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤n1 \le a_i \le n)—— 第 ii 个人为获得幸福感所需共同阅读同一本书的读者人数。

第三行包含一个整数 qq(1≤q≤3⋅1051 \le q \le 3 \cdot 10^5)—— 需要分析的年份数。

接下来的 qq 行中,每行包含一个整数 kjk_j(2≤kj≤n2 \le k_j \le n)—— Velepin 在第 jj 年必须撰写的书本数量。

输出格式

Print qq lines, each of them has exactly one number — the maximum number of people who can be satisfied in jj-th a year if Velepin releases kjk_j books.

输出 qq 行,每行恰好一个数字——即若 Velepin 在第 jj 年发布 kjk_j 本书时,最多能满足的人数。

输入输出样例

  • 输入#1

    5
    1 2 2 2 2
    3
    2
    3
    4

    输出#1

    5
    5
    3
  • 输入#2

    6
    1 2 3 4 5 6
    2
    2
    3

    输出#2

    5
    4
  • 输入#3

    6
    4 4 1 4 4 4
    3
    2
    3
    4

    输出#3

    6
    5
    1

说明/提示

In the first example, in the first year, the optimal division is 1,2,2,2,21, 2, 2, 2, 2 (the first book is read by the first person, and everyone else reads the second). In the second year, the optimal solution is 1,2,2,3,31, 2, 2, 3, 3 (the first book is read by the first person, the second book is read by the second and third person, and all the others read the third book). In the third year, the optimal split will be 1,2,3,4,21, 2, 3, 4, 2. Accordingly, the number of satisfied people over the years will be 5,5,35, 5, 3.

In the second example, in the first year, the optimal division is 1,1,1,1,1,21, 1, 1, 1, 1, 2, then everyone will be happy except the 66-th person. In the second year, the optimal division is 1,1,1,1,2,31, 1, 1, 1, 2, 3, then everyone will be happy except the 55-th and 66-th person.

在第一个例子中,第一年最优的分配方案是 1,2,2,2,21, 2, 2, 2, 2(第一本书由第一个人阅读,其余所有人阅读第二本书);第二年最优的分配方案是 1,2,2,3,31, 2, 2, 3, 3(第一本书由第一个人阅读,第二本书由第二和第三个人阅读,其余所有人阅读第三本书);第三年最优的分配方案为 1,2,3,4,21, 2, 3, 4, 2。因此,各年满意人数分别为 5,5,35, 5, 3。

在第二个例子中,第一年最优的分配方案是 1,1,1,1,1,21, 1, 1, 1, 1, 2,此时除第六个人外,其余人均满意;第二年最优的分配方案是 1,1,1,1,2,31, 1, 1, 1, 2, 3,此时除第五和第六个人外,其余人均满意。

输入解题思路,AI测评打分。不知道怎么写?

首页