Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
1,312 views
in Online Assessments by Expert (46,090 points) | 1,312 views

2 Answers

1 like 0 dislike
Best answer
//we can use priority queue to store max after each operation

#include<iostream>

#include<bits/stdc++.h>

using namespace std;

 

int main()

{

   vector<int>arr{20,4,3,1,9};

    int k=4;

    int score=0;

    priority_queue<int>pq;//max heap

    for(int i=0;i<arr.size();i++)

    {

        pq.push(arr[i]);

       

       

    }

   // cout<<ceil((double)20/3);

    while(k--)

    {

     int ele=pq.top();

     score+=ele;

     pq.pop();

     pq.push(ceil((double)ele/3));

    }

    cout<<score;

 

}
by Expert (660 points)
edited by
0 0
Good Job Sanyam!!
0 like 0 dislike

Images of ques

image

 

by Expert (46,090 points)