electro177's blog

By electro177, history, 2 years ago, In English

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

  • Vote: I like it
  • 0
  • Vote: I do not like it