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.
intluckBalance(intk,vector<vector<int>>contests){intluckBalance=0;vector<int>importants;for(inti=0;i<contests.size();i++){if(contests[i][1]==1)importants.push_back(contests[i][0]);}sort(importants.begin(),importants.end());// Check if k is larger than importants.sizeintimportantsLen=importants.size();// if k > importantsLen, skip the following loopif(k>importantsLen)importantsLen=k;// win all possible important contestsfor(inti=0;i<importantsLen-k;// 0, if k > importantsLeni++){luckBalance-=importants[i];}// lose the importantsif(importantsLen>0){for(inti=importantsLen-k;i<importants.size();i++){luckBalance+=importants[i];}}// Lose the rest of contestsfor(inti=0;i<contests.size();i++){if(contests[i][1]==0)luckBalance+=contests[i][0];}returnluckBalance;}
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 →
C++ 11. Solution.