Scoring in Exam

Milly is at the examination hall where she is reading a question paper. She checked the question paper and discovered that there are N questions in that paper. Each question has some score value. Ideally it's like questions requiring more time have more score value and strangely no two questions on the paper require some time to be solved.

She is very excited by looking these questions. She decided to solve K questions while maximizing their score value. Could you please help Milly to determine the exact time she needs to solve the questions.

Example:

Input: n = 5, q = 2, time= {2, 3, 9, 4, 5}, arr = {3, 5, 11, 6, 7},queries = {5, 3}

Output:

23 18

Approach:

C++

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

void scoringInExam(long long nlong long q,
                   long long time[], long long arr[],
                   vector<long long&queries)
{
    vector<pair<long longlong long>> v;
    for (long long i = 0i < ni++)
        v.push_back({arr[i], time[i]});
    sort(v.begin(), v.end());
    long long sum[n];
    sum[n - 1] = v[n - 1].second;
    for (long long i = n - 2i >= 0i--)
        sum[i] = sum[i + 1] + v[i].second;
    for (long long i = 0i < qi++)
    {
        long long k = queries[i];

        long long res = sum[n - k];
        cout << res << "\n";
    }
}
int main()
{
    long long n = 5q = 2;

    long long time[n] = {23945};
    long long arr[n] = {351167};
    vector<long longqueries = {53};

    scoringInExam(nqtimearrqueries);

    return 0;
}


No comments:

Post a Comment