Snackdown 2019 is coming! There are two rounds (round A and round B) after the qualification round. From both of them, teams can qualify to the pre-elimination round. According to the rules, in each of these two rounds, teams are sorted in descending order by their score and each team with a score greater or equal to the score of the team at the K=1500-th place advances to the pre-elimination round (this means it is possible to have more than K qualified teams from each round in the case of one or more ties after the K-th place). Today, the organizers ask you to count the number of teams which would qualify for the pre-elimination round from round A for a given value of K (possibly different from 1500). They provided the scores of all teams to you; you should ensure that all teams scoring at least as many points as the K-th team qualify.
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
int k, n, count = 0;
cin >> n;
int a[n];
cin >> k;
for (int i = 0; i < n; i++)
{
cin >> a[i];
cout << a[i] << " ";
}
int p;
// sort(a, a + n);
for (int i = 0; i < n; i++)
{
// cout << a[i] << " ";
if (a[i] == a[k - 1])
{
p = a[k - 1];
}
}
cout << p << endl;
for (int i = 0; i < n; i++)
{
// cout << a[i] << " "; if (a[i] > p)
if (a[i] > p)
{
count++;
}
for (int j = i + 1; j < n; j++)
{
if (a[i] == a[j])
{
count--;
}
}
}
cout << count;
}