From 3c8c6068d28a4cd3dc02cc2b55bd607109b133c5 Mon Sep 17 00:00:00 2001 From: InigoGutierrez Date: Thu, 24 Dec 2020 17:26:57 +0100 Subject: Resuelto 248 en c++: Los premios de las tragaperras. --- c/248_losPremiosDeLasTragaperras.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 c/248_losPremiosDeLasTragaperras.cpp (limited to 'c') diff --git a/c/248_losPremiosDeLasTragaperras.cpp b/c/248_losPremiosDeLasTragaperras.cpp new file mode 100644 index 0000000..4a82ff4 --- /dev/null +++ b/c/248_losPremiosDeLasTragaperras.cpp @@ -0,0 +1,33 @@ +#include + +int main(void) { + + int size, best, acc, initBonus, initAcc, last, i; + std::cin >> size; + + while (size != 0) { + + acc = 0; + best = 0; + initBonus = 0; + initAcc = 0; + last = 0; + + for (i = 0; i < size; i++) { + std::cin >> last; + + acc += last; + if (acc < 0) acc = 0; + if (acc > best) best = acc; + + initAcc += last; + if (initAcc > initBonus) initBonus = initAcc; + } + + std::cout << std::max(best, acc+initBonus) << '\n'; + std::cin >> size; + + } + + return 0; +} -- cgit v1.2.1