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 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 .
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 .
More formally tell the number of pairs (marksi, marksj) such that
marksi + marksj=K.
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 n, int k, int a[]){int c[100000] = {0};int sum = 0;int m, maxi;maxi = 0;for (int i = 0; i < n; i++){m = a[i];c[m] = c[m] + 1;if (maxi <= a[i])maxi = a[i];}for (int i = 0; i <= maxi; i++){int j = c[i];if (j > 0){int temp = k - i;if (temp == k / 2){for (int t = c[temp] - 1; t >= 0; t--){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 = 7, k = 8;int a[n] = {3, 5, 6, 3, 2, 1, 3};cout << lalEvaluation(n, k, a) << "\n";return 0;}
No comments:
Post a Comment