Aman and lab file work

Coca cola canteen of Bharati Vidyapeeth University has n hungry students waiting in line. Each unique order, i , is placed by a student at time ti, and the order takes di units of time to process.

Now canteen in charge wanted to know the sequence in which the orders will be completed so that order which is completed first is served first which resulting in less chaos in the canteen during the break hours but he doesn't know how to solve this problem, so he asks Aman but Aman is busy completing unnecessary lab files(No one knows what is the use of writing the lab file, external even doesn't see what we have written inside the file) as other students, so he asks you to solve this problem Given the information for all n orders, can you find and print the order in which all n students will receive their orders? If two or more orders are fulfilled at the exact same time t, sort them by ascending order number.

Example:

Input:  n = 5, v ={{8, 1}, {4, 2}, {5, 6}, {3, 1}, {4, 3}}
Output: 4 2 5 1 3 

Approach

C++

#include <bits/stdc++.h>
using namespace std;

void labFileWork(int nvector<pair<intint>> &v)
{

    vector<pair<intint>> vec;
    for (int i = 0i < ni++)
    {
        int x = v[i].firsty = v[i].second;
        vec.push_back({x + yi + 1});
    }
    sort(vec.begin(), vec.end());
    for (int i = 0i < ni++)
    {
        cout << vec[i].second << " ";
    }
}
int main()
{

    int n = 5;

    vector<pair<intint>> v = {{81},
                                {42},
                                {56},
                                {31},
                                {43}};

    labFileWork(nv);

    return 0;
}


No comments:

Post a Comment