Prefer standard headers
<bits/stdc++.h>
isn't in any standard; even on those platforms where it exists, it's probably a poor choice if it includes the whole of the Standard Library. Instead, include (only) the standard library headers that declare the types that are required for the header.
Avoid using namespace std;
Bringing all names in from a namespace is problematic; namespace std
particularly so. See Why is "using namespace std" considered bad practice?.
Prefer C++ standard headers
Instead of <stdlib.h>
, it's better to include <cstdlib>
, so that standard library names are consistently declared in the std
namespace, away from your own identifiers (though, at a first glance, I don't see where you need this particular header).
Now to the implementation of luckBalance()
. One thing we can observe here is that we only ever use i
to iterate through the elements of contests
; that's a good indication that we can use a range-based for
loop. Since we only read from contests[i]
(and never write), we can use a const reference (and should have accepted a reference to const vector as function argument):
for (const auto& contest: contests) {
if (contest[1] == 1) {
totalLostLuck += contest[0];
(This is a partial review; I intend to return and complete it later).
- 87.9k
- 14
- 104
- 325