We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
int n,k;
cin >> n >> k;
vector <int> impt;
int impt_sum=0;
int unimpt_sum=0;
for (int i=0;i<n;i++) {
int luck,type;
cin >> luck >> type;
if (type) {
impt.push_back(luck);
impt_sum+=luck;
}
else
unimpt_sum+=luck;
}
sort(impt.begin(),impt.end());
int isize=impt.size();
if (k<=isize) for (int i=isize-k-1;i>=0;i--) impt_sum-=(2*impt[i]);
cout << impt_sum+unimpt_sum;
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Luck Balance
You are viewing a single comment's thread. Return to all comments →