From 1d1f9e1e713a8b6a786f2b191d8a9db5f1dca79f Mon Sep 17 00:00:00 2001 From: Syndamia Date: Tue, 13 Jun 2023 21:09:43 +0300 Subject: [DAA/P/HW4] Solved --- .../Practicum/Homeworks/HW4-Sequence.cpp | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Year 2/Design and analysis of algorithms/Practicum/Homeworks/HW4-Sequence.cpp 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 +#include +#include +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])); +} -- cgit v1.3.1-23-gd82d