Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. int luckBalance(int k, vector<vector<int>> contests) {
  2. int max_luck {0};
  3. multiset<int> important_contests;
  4. for (auto e : contests){
  5. if (e[1] == 0){
  6. max_luck += e[0];
  7. } else {
  8. important_contests.insert(e[0]);
  9. }
  10. }
  11. int i{0};
  12. int t;
  13. if (important_contests.size() > k)
  14. t = important_contests.size() - k;
  15. else t = 0;
  16. for (auto e : important_contests){
  17. if (i < t){
  18. max_luck -= e;
  19. ++i;
  20. } else {
  21. max_luck += e;
  22. }
  23. }
  24. return max_luck;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement