Comments

ahh , now i see it // i forgot to verify the conditon with aim>=0 ;;; wasted almost whole hr of contest forgetting to check smth so basic, thanks!

Brother i would really appreciate if you could help me here like where did i mess up the derivation

help me where i went wrong

so either all bordering elements are deleted or multiplied

so either no*of unique elements are deleted ; or they are multiplied

so u can assume for any set ( 1,1,2,2,2,3,3,3)

is equal to (1,2,2,3,3) cause u can easily get it as diff would be divisible by the no of unique elements present

and if we are aiming for size k : it wouldnt matter if we started on either of those above array i gave u

lets save that above array as freq {1,2,2 }

here since bordering element are same deleted or same added

if for a k ;; a element with freq f is present in that construction then b element with freq f also must be present in that condition and would be in the same way to reach that construction

starting from lowest freq 1 , cause ;;

if we do any operation 1 would be gone and wouldnt be able to contribute in further formation of arrangements that reaches 'k'

and for that elem with freq 1 to reach the element whilst its present ; it must have a min freq of [1] ;;

so the difference of element caused to make that element reach that freq of one so we can further construct would be —

Current_freq_total — or n number of element lets say n ;

so while making it one all the element having frequency greater than or equal to 1 will also lose equal amount of freq -> let that unique number be occurence -- and it would also be the no we will lose or gain if we do further operation in it

so diff = n — { occurence * (currentfreq — 1) ) ::

also here occurence would be

so ;; our aim is size = k

so to be able to reach size_k ;;;

it would have to be aim = diff + x*occurence ;;;

or for this to be feasible ;; aim- diff % occurence should be 0 ; so if this is the case we do ans ++ ?? no where did i mess up my derivation

it fails on the test case

3 1 1 2 2 ****

it gives 2 instead of 1 its supposed to output and this is the main codeblock

// unique occuring sorted frequency ;;; 
// occurence[x] -> how many times x or greater element occurs ;;
// exact-> exactly this frequency occurs this many times 

    int ans = 0 ; 
    FOR(i,0,sz(freq)) 
    {
        int diff = n - (occurrence[freq[i]] * (freq[i] -1) ) ; 
        int aim = k ; 
        
        aim -= diff ; 
        if(aim % occurrence[freq[i]] == 0) ans ++ ; 
        n -= (exact[freq[i]] * freq[i])  ;
    }

Thanks for your time , really appreciated ;;