CF1868B2 Candy Party (Hard Version)
题目描述
有 $n$ 个人,第 $i$ 个人有 $a_i$ 颗糖,在派对上,每个人 **至多会做一次下面的事情** :
- 选一个正整数 $p\ (\ 1 \leq p \leq n\ )$ 和一个非负整数 $x$ ,然后把 $2^x$ 颗糖给第 $p$ 个人。注意任意时刻一个人手上的糖不能变成负数,并且一个人不能把糖给自己,每个人只能接受至多一个人的糖。
你需要回答能否在上述操作后让每个人手中的糖果数量相同。
注意本题和 Easy Version 不同的是本题可以不接受糖果,也可以不给出糖果。
输入格式
**本题有多组数据**。
第一行一个整数 $t\ (1 \leq t \leq 1000)$ ,表示数据组数。
对于每组数据:
第一行一个整数 $n\ (1 \leq n \leq 2\ ·10^5)$ 。
接下来一行 $n$ 个整数,表示$a_i\ (1 \leq a_i \leq 10^9)$。
保证对于所有数据,$\sum n \leq 2\ ·10^5$ 。
输出格式
对于每组数据输出一行, "Yes" 代表存在一种方案满足要求,否则输出 "No" 。
对大小写不敏感。
说明/提示
In the first test case, the second person gives $ 1 $ candy to the first person, then all people have $ 3 $ candies.
In the second test case, the fourth person gives $ 1 $ candy to the second person, the fifth person gives $ 2 $ candies to the first person, the third person does nothing. And after the swaps everyone has $ 3 $ candies.
In the third test case, it's impossible for all people to have the same number of candies.
In the fourth test case, the two people do not need to do anything.