aboutsummaryrefslogtreecommitdiff
path: root/semestr-4/aisd/pracownia2/rozw.cpp
blob: dd0d70097541421b6fa9e319fa500b753732bd27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <bits/stdc++.h>
using namespace std;

const int MAX_SUM = 1e6;
const int N = 2e3 + 10;

unordered_map<int, int> sums;
vector<pair<int, int>> 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);
    }
}