Another Solution For Last Round Div.2 D

Revision en1, by xcx0902, 2024-02-12 10:49:30

Consider checking $$$k$$$ one by one. Let $$$sq$$$ be $$$\sum_{i=1}^n a_i$$$. For each $$$k \le sq$$$, calculate the strength in $$$O(n)$$$. For the other $$$k$$$, pre-calculate the contribution of $$$c_i \le sq$$$ (their contribution won't change when $$$k > sq$$$). Then we calculate each $$$c_i > sq$$$ (At most $$$sq$$$ occupation of $$$c_i$$$ that $$$c_i > sq$$$). So the total complexity is $$$O(n \cdot sq)$$$.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English xcx0902 2024-02-12 10:49:30 404 Initial revision (published)