Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

hoacrux's blog

By hoacrux, history, 3 years ago, In Russian

decompose an array of size N into contiguous subarrays of size A each chooses exactly B elements out of n elements from the original array such that

1) every continuous subarray has at least one element in common with the chosen elements and 2) sum of chosen elements is maximum

constraints

1<=N<=100 1<=A<=100 1<=B<=100 1<=A[i]<=10^6

Return the maximum sum all the chosen elements

My first approach is Pick Maximum element in a subarray of size A , and store these maximum in a set Now while set size is less than B pick larger elements which are not in set.

But that is not giving correct answer?

Can anybody tell the approach for this problem effectively?

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