Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #define debug(tl) cerr<<#tl<<' '<<tl<<'\n';
- #include "bits/stdc++.h"
- using namespace std;
- #define all(d) d.begin(), d.end()
- typedef long long ll;
- constexpr int N = 5e4 + 1;
- bitset<N> dp[51][51];
- signed main() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int t; cin >> t;
- while (t--) {
- int n; cin >> n;
- vector<int> a(n);
- int sum = 0;
- for (int i = 0; i < n; i++) {
- cin >> a[i];
- sum += a[i];
- }
- bitset<N> dp2[51];
- sort(all(a));
- int x = 0, ans = 0;
- for (int i = 1; i <= n; i++) {
- bitset<N>dp1[51];
- dp1[0][0] = 1;
- dp2[0][0] = 1;
- for (int k = 1; k <= n; k++) {
- for (int j = a[0]; j < sum; j++) {
- dp1[k][j] = dp2[k][j];
- if (a[i - 1] > j) {
- continue;
- }
- else {
- dp1[k][j] = (dp1[k][j] | dp2[k - 1][j - a[i - 1]]);
- }
- }
- }
- for (int i = 0; i <= n; i++) {
- dp2[i] = dp1[i];
- }
- }
- for (int j = a[0]; j <= sum; j++) {
- int cnt = 0;
- bool dp1 = false;
- for (int k = 1; k <= n; k++) {
- cnt += dp2[k][j];
- }
- if (cnt > ans) {
- x = j; ans = cnt;
- }
- }
- cout << ans << ' ' << x << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement