diff options
1 files changed, 23 insertions, 0 deletions
| -rw-r--r-- | Year 2/Design and analysis of algorithms/Practicum/Homeworks/HW4-Sequence.cpp | 23 |
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])); +} |
