# #DOTIFYPLAY

### My issue

It is showing that 1 is correct 1 is WA,
I created a separate vector consisting of the song with same language and then sorted it and reversed it to find the maximum length of the playlist:
until k is reached!

### My code

``````#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
void solve()
{
int n, k, l;
cin >> n >> k >> l;
int m[n], L[n];
for (int i = 0; i < n; i++)
{
cin >> m[i] >> L[i];
}
vector<int> len;
int size{0};
for (int i = 0; i < n; i++)
{
if (L[i] == l)
{
len.push_back(m[i]);
size++;
}
}
if (size != 0)
{
int max_length = 0;
int term = 0;
sort(len.begin(), len.end());
for (int i = len.size() - 1; i >= 0; i--)
{
term++;
if (term > k)
{
break;
}
else
{
max_length += len.at(i);
}
}
cout << max_length << endl;
}else if(size==0){
cout<<"-1"<<endl;
}
}
int main()
{
int n;
cin >> n;
while (n--)
{
solve();
}
}
``````

Problem Link: DOTIFYPLAY Problem - CodeChef

i got the same problem with python

``````from functools import reduce

# Read the number of test cases
for _ in range(int(input())):
n, k, l = map(int, input().split())
values = set()
for _ in range(n):
a, b = map(int, input().split())
if b == l:

# Sort the unique values
sorted_values = sorted(values, reverse=True)
q=len(sorted_values)
for i in range(q-1):
if sorted_values[i] == sorted_values[i+1]:
sorted_values.remove(sorted_values[i])
if len(sorted_values) == 0 or len(sorted_values) == k or k>len(sorted_values):
print(-1)
elif len(sorted_values) == k:
print(sum(sorted_values))
elif len(sorted_values)==2:
print(max(sorted_values))
elif k<len(sorted_values):
for i in range(k):
sorted_values.pop()
sum=0
for i in range(k):
sum+=sorted_values[i]
print(sum)
``````