How to solve this problem ? SOLVED()

Правка en9, от atlasworld, 2019-06-13 23:02:06

Given an array A of N numbers, you have to perform B operations. In each operation, you have to pick any one of the N elements and add original value(value stored at index before we did any operations) to it's current value. You can choose any of the N elements in each operation.

Perform B operations in such a way that the largest element of the modified array(after B operations) is minimised. Return an integer corresponding to the minimum possible largest element after K operations.

Example:

Input : A = [1, 2, 3, 4] B = 3

Output : 4

Explanation : After the 1st operation the array would change to [2, 2, 3, 4] After the 2nd operation the array would change to [3, 2, 3, 4] After the 3rd operation the array would change to [4, 2, 3, 4]

A : [ 8, 6, 4, 2 ] B : 8 The expected returned value : 12

Thanks : the problem is solved, one more way to solve this problem is to use min heap priority queue with the following comparator

struct op
{
    bool operator()(const pll &a , const pll &b)
    {
        return a.fi + a.se > b.fi + b.se; /// greater than bcoz min and max works reverse in comparator, what i observed till now.
    }
};

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en9 Английский atlasworld 2019-06-13 23:02:06 89
en8 Английский atlasworld 2019-06-13 22:59:07 3 Tiny change: 'lem is sold, one mor' -> 'lem is solved, one mor'
en7 Английский atlasworld 2019-06-13 22:55:02 284
en6 Английский atlasworld 2019-06-13 21:41:23 59
en5 Английский atlasworld 2019-06-13 21:35:03 50
en4 Английский atlasworld 2019-06-13 21:33:16 32
en3 Английский atlasworld 2019-06-13 21:32:59 84 Reverted to en1
en2 Английский atlasworld 2019-06-13 21:32:45 84
en1 Английский atlasworld 2019-06-13 21:32:27 875 Initial revision (published)