From 3ece8214fbf6389d0fabb63a9040720757c7db71 Mon Sep 17 00:00:00 2001 From: Franciszek Malinka Date: Tue, 30 Mar 2021 20:00:11 +0200 Subject: zmiana nazw --- Semestr 4/aisd/pracownia2/rozw.cpp | 59 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Semestr 4/aisd/pracownia2/rozw.cpp (limited to 'Semestr 4/aisd/pracownia2/rozw.cpp') diff --git a/Semestr 4/aisd/pracownia2/rozw.cpp b/Semestr 4/aisd/pracownia2/rozw.cpp new file mode 100644 index 0000000..dd0d700 --- /dev/null +++ b/Semestr 4/aisd/pracownia2/rozw.cpp @@ -0,0 +1,59 @@ +#include +using namespace std; + +const int MAX_SUM = 1e6; +const int N = 2e3 + 10; + +unordered_map sums; +vector> v; + +int main() { + int n; + scanf("%d", &n); + sums[0] = 0; + for (int i = 0; i < n; i++) { + int h; + scanf("%d", &h); + v.clear(); + for (auto kv: sums) { + v.push_back(kv); + } + + for (auto kv: v) { + int dif = kv.first, best = kv.second; + cout << dif << " " << best << "\n"; + int aux = 0; + if (dif >= 0) { + aux = h; + } else if (dif + h > 0) { + aux = dif + h; + } + + cout << ">aux: " << aux << " "; + sums[dif + h] = max(sums[dif + h], best + aux); + aux = 0; + if (dif <= 0) { + aux = h; + } else if (dif - h < 0) { + aux = h - dif; + } + cout << aux << "\n"; + sums[dif - h] = max(sums[dif - h], best + aux); + } + cout << "---\n"; + } + for (auto kv: sums) { + printf("%d %d\n", kv.first, kv.second); + } + + if (sums[0] != 0) { + printf("TAK\n%d\n", sums[0]); + } else { + int mini = 1e9; + sums.erase(0); + for (auto kv: sums) { + mini = min(mini, abs(kv.first)); + } + printf("NIE\n%d\n", mini); + } +} \ No newline at end of file -- cgit v1.2.3