Created
May 25, 2015 10:27
-
-
Save ntnmrndn/ad20117d615cdc489e65 to your computer and use it in GitHub Desktop.
This file contains 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
// you can write to stdout for debugging purposes, e.g. | |
// printf("this is a debug message\n"); | |
int cost(int A[], size_t P, size_t Q) { | |
return A[P] + A[Q]; | |
} | |
size_t smallest(int A[], size_t P, size_t N) { | |
size_t i = P; | |
for (min = A[P]; ) | |
} | |
int solution(int A[], int N) { | |
int solution = cost(A, 1, 3); | |
size_t next_smallest = 3; | |
for (size_t P = 1; P < N - 2; ++P) { | |
if (A[P] >= solution) { // costs are strictly positives | |
continue; | |
} | |
for (size_t Q = P + 2; Q < N - 1; ++Q) { | |
int current_cost = cost(A, P, Q); | |
if (current_cost < solution) { | |
solution = current_cost; | |
} | |
} | |
} | |
return solution; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment