#P13784. [eJOI 2022] Game With Numbers

[eJOI 2022] Game With Numbers

题目描述

Two players are playing a game. They are given an array a1,a2,,ana_1, a_2, \ldots, a_n as well as an array b1,b2,,bmb_1, b_2, \ldots, b_m.

The game consists of mm rounds. Players are participating in rounds alternatively. During the ii-th round (for ii from 1 to mm) the corresponding player (first player, if ii is odd, and second if ii is even) has to do exactly one of the following:

  • remove all elements from the array aa that are divisible by bib_i,
  • remove all elements from the array aa that are not divisible by bib_i.

The first player wants to minimize the sum of the remaining elements in the array aa after all mm rounds, and the second wants to maximize it. Find the sum of the remaining elements in the array aa after all mm rounds if both players are playing optimally.

输入格式

The first line contains two integers n,mn, m (1n21041 \leq n \leq 2 \cdot 10^4, 1m21051 \leq m \leq 2 \cdot 10^5) - the length of the array aa and the number of rounds in the game.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (41014ai41014-4 \cdot 10^{14} \leq a_i \leq 4 \cdot 10^{14}) - the elements of the array aa.

The third line contains mm integers b1,b2,,bmb_1, b_2, \ldots, b_m (1bi410141 \leq b_i \leq 4 \cdot 10^{14}) - the elements of the array bb.

输出格式

Output a single integer - the sum of the remaining elements of the array aa after all mm rounds if both players are playing optimally.

6 2
2 2 5 2 2 7
2 5
7
5 1
-5000111000 -5000222000 -15 5 2
5
-10000333010

提示

Note

In the first sample, one possible flow of the game is the following:

  • Round 1: first player removes from aa all elements divisible by 22. aa becomes (5,7)(5, 7).
  • Round 2: second player removes from aa all elements divisible by 55. aa becomes (7)(7). If he had removed from aa all elements not divisible by 55, aa would become (5)(5), which has a smaller sum of elements and therefore is not desirable for the second player.

Scoring

  1. (3 points): m=1m = 1
  2. (6 points): bi+1=bib_{i+1} = b_i (1i<m1 \leq i < m), i.e. all elements of the array bb are the same
  3. (15 points): bi+1modbi=0b_{i+1} \mod b_i = 0 (1i<m1 \leq i < m)
  4. (9 points): 1m71 \leq m \leq 7
  5. (11 points): 1m201 \leq m \leq 20
  6. (15 points): 1m1001 \leq m \leq 100
  7. (18 points): 1ai,bi1091 \leq a_i, b_i \leq 10^9
  8. (11 points): mmod2=0m \bmod 2 = 0, b2i1=b2ib_{2i-1} = b_{2i} (1im21 \leq i \leq \frac{m}{2})
  9. (12 points): No additional constraints