QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#582#353598#7403. Subset Sum5sbieeSuccess!2024-03-21 08:27:132024-03-21 08:27:13

Details

Extra Test:

Wrong Answer
time: 94ms
memory: 3764kb

input:

200
100 1000000
19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19999 19...

output:

1000000
1000000
1000000
999998
1000000
1000000
1000000
1000000
1000000
1000000
1000000
1000000
1000000
1000000
1000000
1000000
999999
999997
999997
999999
1000000
1000000
1000000
1000000
1000000
1000000
1000000
1000000
1000000
1000000
1000000
1000000
1000000
1000000
1000000
1000000
999995
1000000
10...

result:

wrong answer 4th numbers differ - expected: '1000000', found: '999998'

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#353598#7403. Subset SumieeWA 95ms4056kbC++23759b2024-03-14 11:52:542024-03-21 08:27:42

answer

#include <bits/stdc++.h>
using namespace std;
void solve() {
	int n, c;
	cin >> n >> c;
	vector<int> a(n);
	for (int &x : a) {
		cin >> x;
	}
	sort(a.begin(), a.end());
	int w = 0;
	for (int &x : a) {
		if (x <= c) {
			c -= x;
			w += x;
			x *= -1;
		}
	}
	static mt19937 eng(chrono::steady_clock::now().time_since_epoch().count());
	constexpr int N = 2e5 + 5;
	bitset<N + N> f;
	f[N] = 1;
	shuffle(a.begin(), a.end(), eng);
	for (int x : a) {
		if (x > 0) f |= f << x;
		else f |= f >> -x;
	}
	c = min(c, N - 1);
	for (int i = N + c; ; i--) {
		if (f[i]) {
			cout << i - N + w << "\n";
			return;
		}
	}
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	int t;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}