Hello, I wrote a code for ADAFRIEN - Ada and Friends problem but my code is failing some test case. Please, can anyone tell me what am I missing? I have run it on all example test case and it is giving correct output for those.
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <numeric>
#include <algorithm>
using namespace std;
int main(){
map<string,long long> m;
vector<long long> v;
long long q,k;
cin>>q>>k;
for(long long i=0;i<q;i++){
string s;
long long n;
cin>>s;
cin>>n;
if(m.find(s)!=m.end()){
m[s]+=n;
}
else{
m.insert({s,n});
}
}
for(auto it:m){
v.push_back(it.second);
}
sort(v.begin(),v.end(),greater<long long>());
long long x;
if(k<=m.size()){
x = accumulate(v.begin(),v.begin()+k,0);
}
else{
x = accumulate(v.begin(),v.end(),0);
}
cout<<x;
return 0;
}