LAL Evaluation

You want a good CGPI then it is necessary to make a good CGPI in LAL( There is no need to say about its difficulty ).

Come to a hypothetical situation that happened in LAL. There has been a strange evaluation of 105 marks and there are N students who got marks between 0 and 105 ( Both 0 and 105 are inclusive, Yes there are some studious mathematicians also who got full marks). Now, there is a strange grading system also i.e.

Those pairs (student i, student j) of students will get A+ if the sum of marks  of i and j is the lucky number K .

You didn't participate in this strange evaluation but it is necessary to know your classmates' results. So, tell the number of pairs of students who have sum of marks K.

More formally tell the number of pairs (marksi, marksj)  such that 

     marks+ marksj=K.  1i<jN


Example:

Input:  n = 7, k = 8, a[n] = {3, 5, 6, 3, 2, 1, 3}
Output: 4

Approach

C++

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

int lalEvaluation(int nint kint a[])
{
    int c[100000] = {0};
    int sum = 0;
    int mmaxi;
    maxi = 0;
    for (int i = 0i < ni++)
    {

        m = a[i];
        c[m] = c[m] + 1;
        if (maxi <= a[i])
            maxi = a[i];
    }

    for (int i = 0i <= maxii++)
    {
        int j = c[i];
        if (j > 0)
        {
            int temp = k - i;
            if (temp == k / 2)
            {
                for (int t = c[temp] - 1t >= 0t--)
                {
                    sum = sum + t;
                }
            }
            else if (temp >= 0)
            {
                if (c[temp] > 0)
                {
                    sum = sum + (c[temp] * j);
                    c[temp] = 0;
                }
            }
        }
    }
    return sum;
}
int main()
{
    int n = 7k = 8;

    int a[n] = {3563213};

    cout << lalEvaluation(nka<< "\n";

    return 0;
}


No comments:

Post a Comment