Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- vector<int> v;
- long long getmindiff(vector<int> v) {
- int n = v.size();
- long long sumAll = 0;
- for (auto num : v)
- sumAll += num;
- bool isOdd = (sumAll & 1);
- sumAll >>= 1;
- vector<int> dp(sumAll + 1, false);
- dp[0] = true;
- for (int i = 0; i < n; ++i)
- for (long long j = sumAll; j >= v[i]; --j)
- dp[j] = dp[j] || dp[j - v[i]];
- int result = 0;
- for (long long i = sumAll; i > 0; --i) {
- if (dp[i]) {
- result = (sumAll - i) << 1;
- break;
- }
- }
- return int(isOdd ? result + 1 : result);
- }
- void func() {
- int n = 0;
- cin >> n;
- for (int i = 0; i < n; i++) {
- int a = 0;
- cin >> a;
- v.push_back(a);
- }
- for (int i = 0; i < n; i++) {
- vector<int> v_ = v;
- v_[i] = 0;
- int diff = getmindiff(v_);
- if (diff < v[i]) {
- cout << 1;
- } else {
- cout << 0;
- }
- if (i != n - 1) {
- cout << " ";
- } else {
- cout << endl;
- }
- }
- }
- int main() {
- int T = 0;
- cin >> T;
- for (int i = 0; i < T; i++) {
- func();
- v.clear();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement