Created
November 24, 2017 21:37
-
-
Save Florian3k/154080e34754a71590758686a3d21aef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int calcLoad(int sectors[], int n) | |
{ | |
//return 0; | |
if (n > 43) | |
{ | |
n = 43; | |
} | |
int max = std::accumulate(sectors, sectors + (n > 7 ? 7 : n), 0); | |
if (n <= 7) | |
{ | |
return max; | |
} | |
int nextRange = 12; | |
int elements = 6; | |
for (;;) | |
{ | |
auto last = sectors + (nextRange + 1 > n ? n : nextRange + 1); | |
auto middle = last - elements; | |
auto first = middle - 7; | |
if (first < sectors) | |
{ | |
first = sectors; | |
} | |
std::nth_element(first, middle, last); | |
int sum = std::accumulate(middle, last, 0); | |
max = max > sum ? max : sum; | |
if (elements > 1 && nextRange + 1 < n) | |
{ | |
nextRange += 6; | |
elements -= 1; | |
} | |
else | |
{ | |
break; | |
} | |
} | |
return max; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment