Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
3,168 views

in Online Assessments by Expert (108,690 points) | 3,168 views

1 Answer

0 like 0 dislike
#include<bits/stdc++.h>

using namespace std;

//time :- O(n)  || Space :- O(n) where n = no of processors

int findTotalExecutionTime(vector<int>& execution){
    unordered_map<int, int> map;
    for(auto it : execution)
        map[it] += 1;

    long result = 0LL;
    for(auto it : map){
        int time = it.first;
        int noOfProcessors = it.second;
        while(time > 0 && noOfProcessors > 0){
            result += time;
            noOfProcessors--;
            time = ceil(time / 2.0);
        }
    }

    return result;
}

int main(){
    int n;
    cin >> n;
    vector<int> execution;
    while(n > 0){
        int time;
        cin >> time;
        execution.push_back(time);
        n--;
    }

    cout << findTotalExecutionTime(execution) << endl;

    return 0;
}
by (140 points)