#P16544. [EGOI 2026] 蛋糕 / Cakes

    ID: 18917 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>贪心枚举2026EGOI(欧洲/女生)整除分块

[EGOI 2026] 蛋糕 / Cakes

Problem Description

Liliana’s birthday is coming, and she has invited all her best friends to celebrate. To make the party more special, she plans to prepare several cakes, each decorated with various toppings such as strawberries, almonds, or praline. Liliana has NN types of toppings, and for each topping ii she has aia_i pieces.

A cake’s “deliciousness” is defined as the maximum number of occurrences of any single topping on that cake. For example:

  • If a cake has toppings 1,1,2,2,2{1, 1, 2, 2, 2}, then its deliciousness is 33, because topping 22 appears three times.
  • If a cake has toppings 0,0,1,1,2{0, 0, 1, 1, 2}, then its deliciousness is 22, because both topping 00 and topping 11 appear twice, and no other topping appears more times.

Liliana wants to bake several cakes that all have the same deliciousness, and she must use all toppings with nothing left over. She has not decided how many cakes to bake. She is considering QQ plans, each plan specifying a number of cakes KjK_j. For each plan, determine whether it is possible to distribute all toppings among KjK_j cakes such that every cake has the same deliciousness. The total number of toppings on each cake may be different, but each cake must contain at least one topping. Note that different cakes may contain different numbers of topping types.

Input Format

The first line contains two integers NN and QQ, representing the number of topping types and the number of plans. The second line contains NN integers a0,a1,,aN1a_0, a_1, \dots, a_{N-1}, where aia_i is the number of pieces of topping ii. The next QQ lines each contain one integer KjK_j, specifying the number of cakes required in the jj-th plan.

Output Format

Output QQ lines. If it is possible to distribute all toppings among KjK_j cakes with the same deliciousness, output YES on the jj-th line; otherwise output NO.

4 5
2 5 1 1
1
2
3
4
5
YES
NO
YES
NO
YES
1 1
4
2
YES
5 3
1 1 1 1 1
1
1000000000000000000
5
YES
NO
YES

Hint

Sample Explanation

In the first sample, Liliana has four topping types: two pieces of topping 0 (shown as green triangles), five pieces of topping 1 (shown as yellow stars), one piece of topping 2 (shown as an orange circle), and one piece of topping 3 (shown as a blue square).

When K=1K = 1, Liliana can make one cake with deliciousness 55 by putting all toppings on a single cake:

  • Cake 1: {0,0,1,1,1,1,1,2,3}\{0, 0, 1, 1, 1, 1, 1, 2, 3\} (topping 1 appears five times).

    :::align{center}

    An example distribution for K=1K = 1. :::

When K=2K = 2, Liliana cannot distribute all toppings into two cakes with the same deliciousness.

When K=3K = 3, Liliana can make 33 cakes, each with deliciousness 22, distributed as follows:

  • Cake 1: 0,0,1{0, 0, 1} (topping 0 appears twice).

  • Cake 2: 1,1,2{1, 1, 2} (topping 1 appears twice).

  • Cake 3: 1,1,3{1, 1, 3} (topping 1 appears twice).

    :::align{center}

    An example distribution for K=3K = 3. :::

When K=4K = 4, Liliana cannot distribute all toppings into four cakes with the same deliciousness.

When K=5K = 5, Liliana can make 55 cakes, each with deliciousness 11, distributed as follows:

  • Cake 1: 0,1{0, 1} (topping 0 and topping 1 each appear once).

  • Cake 2: 0,1{0, 1} (topping 0 and topping 1 each appear once).

  • Cake 3: 1{1} (topping 1 appears once).

  • Cake 4: 1,2{1, 2} (topping 1 and topping 2 each appear once).

  • Cake 5: 1,3{1, 3} (topping 1 and topping 3 each appear once).

    :::align{center}

    An example distribution for K=5K = 5. :::

Constraints

  • 1N,Q100 0001 \leq N, Q \leq 100\ 000.
  • 1ai100 0001 \leq a_i \leq 100\ 000.
  • 1Kj10181 \leq K_j \leq 10^{18}.

Scoring

Your program will be tested on testdata divided into several subtasks. To get the score for a subtask, you must solve all the testdata in that subtask correctly.

  • Subtask 00 [00 points]: Samples.
  • Subtask 11 [99 points]: N=1N = 1.
  • Subtask 22 [2222 points]: Q=1Q = 1 and Kj=2K_j = 2.
  • Subtask 33 [2424 points]: Q5,N1000,ai1000Q \le 5, N \le 1000, a_i \le 1000.
  • Subtask 44 [2424 points]: Q5Q \le 5.
  • Subtask 55 [2121 points]: No additional constraints.

Translated by ChatGPT 5