aboutsummaryrefslogtreecommitdiff
path: root/c
diff options
context:
space:
mode:
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;
+}