P18157 [NWERC 2026] Fighting Food Waste

Description

After a big party, Feli is left with $n$ dishes that none of her guests managed to eat. The dishes are numbered from $1$ to $n$. Each dish has a *remaining shelf life*, measured in days. Right after the party, dish $i$ has a remaining shelf life of $d_i$ days. A dish is edible as long as its remaining shelf life is nonnegative. To avoid wasting any food, Feli plans to eat one dish on each of the $n$ days following the party. She will not eat any spoiled food, though. Fortunately, Feli has a fridge that can store up to $k$ dishes at a time. When she puts a dish in the fridge, its remaining shelf life immediately doubles. Removing a dish from the fridge immediately halves its remaining shelf life. This may result in a non-integer remaining shelf life. Feli can put dishes in the fridge right after the party. On each of the $n$ days following the party, the remaining shelf life of each uneaten dish first decreases by $1$, whether or not it is in the fridge. After this, Feli can take dishes out of the fridge and put dishes in the fridge as she wishes, provided that the fridge never contains more than $k$ dishes. Finally, Feli must eat one edible dish that is not in the fridge. Determine whether it is possible for Feli to eat all leftovers before they spoil.

Input Format

The input consists of: - One line with two integers $n$ and $k$ ($1 \leq n \leq 2 \cdot 10^5$, $1 \leq k \leq 2 \cdot 10^5$), the number of dishes and the capacity of the fridge. - One line with $n$ integers $d_1, \dots, d_n$ ($1 \leq d_i \leq 10^6$ for each $i$), where $d_i$ is the remaining shelf life of the $i$th dish right after the party.

Output Format

If it is possible for Feli to eat all leftovers before they spoil, output “`possible`”. Otherwise, output “`impossible`”.

Explanation/Hint

### Sample 1 Explanation ![image.png](https://cdn.luogu.com.cn/upload/image_hosting/wk9o57or.webp) Figure 1. A possible way to eat all leftovers in Sample 1. Day 0 is the day of the party. Each box shows the state before (left) and after (right) moving dishes in and out of the fridge. Numbers to the right of the dishes show their remaining shelf lives in days.