688E - The Values You Can Make - CodeForces Solution


dp *1900

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <vector>

#define pb push_back

using namespace std;

int n, k;
int a[1000];
bool dp[510][510][510];
int main(){
    cin >> n >> k;
    for (int i = 1; i <= n; ++i){
        cin >> a[i];
    }

    dp[0][0][0] = 1;
    for (int i = 1; i <= n; ++i){
        for (int j = 0; j <= k; ++j){
            for (int p = 0; p <= j; ++p){
                dp[i][j][p] |= dp[i - 1][j][p];
                if (j >= a[i]){
                    dp[i][j][p] |= dp[i - 1][j - a[i]][p];
                }
                if (j >= a[i] && p >= a[i]){
                    dp[i][j][p] |= dp[i - 1][j - a[i]][p - a[i]];
                }
            }
        }
    }

    vector<int> x;
    for (int i = 0; i <= k; ++i){
        if (dp[n][k][i]){
            x.pb(i);
        }
    }
    cout << (int)x.size() << '\n';
    for (auto it : x){
        cout << it << " ";
    }
}/*1687991988.8299892*/


Comments

Submit
0 Comments
More Questions

727A - Transformation from A to B
822B - Crossword solving
1623A - Robot Cleaner
884B - Japanese Crosswords Strike Back
862B - Mahmoud and Ehab and the bipartiteness
429A - Xor-tree
1675C - Detective Task
950A - Left-handers Right-handers and Ambidexters
672B - Different is Good
1C - Ancient Berland Circus
721A - One-dimensional Japanese Crossword
1715B - Beautiful Array
60B - Serial Time
453A - Little Pony and Expected Maximum
1715A - Crossmarket
1715C - Monoblock
1512C - A-B Palindrome
1679B - Stone Age Problem
402A - Nuts
792A - New Bus Route
221A - Little Elephant and Function
492C - Vanya and Exams
1369B - AccurateLee
892B - Wrath
999A - Mishka and Contest
727C - Guess the Array
1625C - Road Optimization
1715D - 2+ doors
267A - Subtractions
1582A - Luntik and Concerts