diff --git a/solving/the-cake-is-a-lie/main.cpp b/solved/the-cake-is-a-lie/main.cpp similarity index 73% rename from solving/the-cake-is-a-lie/main.cpp rename to solved/the-cake-is-a-lie/main.cpp index 11a79c1..50d6f1a 100644 --- a/solving/the-cake-is-a-lie/main.cpp +++ b/solved/the-cake-is-a-lie/main.cpp @@ -64,17 +64,45 @@ int main() { takeI(n); takeV(a,n); // Bessie & elsie - int b, e; /** + + N = 2 + Only bessie gets to take a turn + N = 4 + Bessie gets 2 turns, elsie gets 1 + N = 6 + B 1 1 1 1 1 1 + E 1 1 2 1 1 + B 1 1 2 1 + E 1 3 1 + B 1 3 + E 4 + Bessie gets 3 turns, elsie gets 2 - B: 1, 2, 3 - E: 3, 3 - B: 3 - Each have 3 - + B: 1, 2, 3, 4 + E: 1, 5, 4 + B: 1, 5 + E, 6 + B = 6, E = 4 */ + // Calculate total + ll total = 0; for (auto x : a) total += x; + // Calculate if elsie just picks on the left + int elsieTurns = (n/2) - 1; + ll tmpTotal = 0; + for (int i = 0; i < elsieTurns; i++) tmpTotal += a[i]; + ll e = tmpTotal; + + for (int i = 0; i < elsieTurns; i++) { + tmpTotal -= a[elsieTurns-1-i]; + tmpTotal += a[n-1-i]; + e = max(tmpTotal, e); + } + + ll b = total - e; + cout << b << SP << e << NL; } } diff --git a/solving/the-cake-is-a-lie/the-cake-is-a-lie.in b/solved/the-cake-is-a-lie/the-cake-is-a-lie.in similarity index 100% rename from solving/the-cake-is-a-lie/the-cake-is-a-lie.in rename to solved/the-cake-is-a-lie/the-cake-is-a-lie.in