Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit1d1f9e1e713a8b6a786f2b191d8a9db5f1dca79f (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-06-13 21:09:43 +0300
Committer
 Syndamia <kamen@syndamia.com>
2023-06-13 21:09:43 +0300
Files201bde6888a6141ec6ba30e615eefa81c0f89c61
uni-projects-1d1f9e1e713a8b6a786f2b191d8a9db5f1dca79f.tar
uni-projects-1d1f9e1e713a8b6a786f2b191d8a9db5f1dca79f.tar.gz
uni-projects-1d1f9e1e713a8b6a786f2b191d8a9db5f1dca79f.zip
Parent8365e42b1c53f70ca9e1dc84303cdab6924f0a64 (diff)
[DAA/P/HW4] Solved
1 files changed, 23 insertions, 0 deletions
-rw-r--r--Year 2/Design and analysis of algorithms/Practicum/Homeworks/HW4-Sequence.cpp23
diff --git a/Year 2/Design and analysis of algorithms/Practicum/Homeworks/HW4-Sequence.cpp b/Year 2/Design and analysis of algorithms/Practicum/Homeworks/HW4-Sequence.cpp
new file mode 100644
index 0000000..14c235e
--- /dev/null
+++ b/Year 2/Design and analysis of algorithms/Practicum/Homeworks/HW4-Sequence.cpp
@@ -0,0 +1,23 @@
+#include <iostream>
+#include <cstring>
+#include <stack>
+using namespace std;
+
+long long n;
+long long mult2[100010] = { 0 }, mult3[100010] = { 0 };
+
+int main() {
+ scanf("%lld", &n);
+ for (long long i = 0; i < n; i++) {
+ long long t;
+ scanf("%lld", &t);
+ mult2[i] = t*2;
+ mult3[i] = t*3;
+ }
+
+ for (long long i = 1; i < n; i++) {
+ mult2[i] += max(mult2[i-1], mult3[i-1]);
+ mult3[i] += mult2[i-1];
+ }
+ printf("%lld", max(mult2[n-1], mult3[n-1]));
+}