aboutsummaryrefslogtreecommitdiff
path: root/c
diff options
context:
space:
mode:
authorInigoGutierrez <inigogf.95@gmail.com>2020-12-24 17:26:57 +0100
committerInigoGutierrez <inigogf.95@gmail.com>2020-12-24 17:26:57 +0100
commit3c8c6068d28a4cd3dc02cc2b55bd607109b133c5 (patch)
tree831b4aee17117ce7b78ad9582287ef829797b6d6 /c
parentf22ae4b2ebefe1656069f30f457d2e1631a4705b (diff)
downloadAceptaElReto-3c8c6068d28a4cd3dc02cc2b55bd607109b133c5.tar.gz
AceptaElReto-3c8c6068d28a4cd3dc02cc2b55bd607109b133c5.zip
Resuelto 248 en c++: Los premios de las tragaperras.
Diffstat (limited to 'c')
-rw-r--r--c/248_losPremiosDeLasTragaperras.cpp33
1 files changed, 33 insertions, 0 deletions
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 <iostream>
+
+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;
+}