From f2ac1662504c72122bf9b77fe265095b58dab575 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 10 Apr 2023 09:48:06 +0300 Subject: [DAA/E1] Added work from first exam from yesterday --- .../Practicum/Exam1/2-Shots.cpp | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Year 2/Design and analysis of algorithms/Practicum/Exam1/2-Shots.cpp (limited to 'Year 2/Design and analysis of algorithms/Practicum/Exam1/2-Shots.cpp') diff --git a/Year 2/Design and analysis of algorithms/Practicum/Exam1/2-Shots.cpp b/Year 2/Design and analysis of algorithms/Practicum/Exam1/2-Shots.cpp new file mode 100644 index 0000000..24dadf9 --- /dev/null +++ b/Year 2/Design and analysis of algorithms/Practicum/Exam1/2-Shots.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +#include +using namespace std; + +int main() { + int N = 0; + scanf("%d", &N); + vector m; + long temp = 0; + for (int i = 0; i < N; i++) { + scanf("%ld", &temp); + m.push_back(temp); + } + + int l = 0, r = N - 1; + long lalc = 0, ralc = 0; + long tot = 0; + while (l <= r) { + if (lalc < ralc) + lalc += m[l++]; + else + ralc += m[r--]; + if (lalc == ralc) { + tot = (l - 1 - r) + N; + } + } + + printf("%ld", tot); +} -- cgit v1.3.1-26-gb76a