easy greedy?

Revision en1, by electro177, 2021-11-08 11:15:59

given n(<=5e4) towns .every day we sell product in one of the towns.the towns that are chosen on any successive days should be different and a town i can be chosen max ci(<=n) times.find maximum number of sales? i/p: 3 (n) 7 2 3 (array of n elements) 0/p-11

exp:it is easy to see that use 7 and 2 and make it 5 and 0(ans-4) then 5 and 3 and make it to 2 and 0(ans-6+4).but finally we used a[3] now use a[0] only once ,and so ans is 11

my approach:i thought of using dp and find all possible sums using the array ,and take the nearest middle value,but this will tle and mle for the constraints

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English electro177 2021-11-08 11:15:59 627 Initial revision (published)