{
  "id": 22574629,
  "title": "Meet in the Middle | CSES - Algoritmit ongelmanratkaisussa",
  "url": "https://urgent.news/2026/11/29/meet-in-the-middle-cses-algoritmit-ongelmanratkaisussa",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-29T12:19:15.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/guhan29/meet-in-the-middle-cses-algoritmit-ongelmanratkaisussa-41cd"
  },
  "original_language": null,
  "account": "In the coding challenge CSES - Algorithm Problem Solving, a solution is presented in C++ that calculates the number of ways to partition an array into two subsets with a specific sum. The algorithm utilizes dynamic programming and binary search techniques.\n\nFirst, the necessary header files are included, and the required data structures, such as vectors and arrays, are declared. The `dp` array is initialized to store intermediate results, while `n` represents the size of the input array `arr`. The variable `x` denotes the target sum for the partition.\n\nA helper function `getSubsetSum` is defined, which takes the left and right indices of the array and returns a vector containing all possible subset sums within that range. This function uses bit manipulation to generate all possible combinations of elements and calculates their sums.\n\nIn the `main` function, the input size `n` and the target sum `x` are read from standard input. The array elements are then inputted, and two vectors, `left` and `right`, are created to store the subset sums of the first half and the second half of the array, respectively.\n\nBoth `left` and `right` vectors are sorted in ascending order. The algorithm then iterates through each element `i` in the `left` vector. For each element, binary search is performed on the `right` vector to find the lower and upper bounds of the values that, when subtracted from `i`, equal the target sum `x`. The difference between the upper and lower bounds represents the number of valid ways to partition the array.\n\nFinally, the total count of ways is stored in the `ways` variable and printed to standard output. The program terminates with a return value of 0.",
  "summary": "https://cses.fi/alon/task/1628 #include #include #include #include using namespace std ; int dp [ 41 ] [ 41 ] ; int n ; long long x ; long long arr [ 41 ] ; vector getSubsetSum ( int l , int r ) { int len = r - l + 1 ; vector res ; for ( int i = 0 ; i",
  "summary_source": "publisher",
  "key_points": [
    "CSES problem-solving platform presents C++ solution",
    "Dynamic programming and binary search techniques used",
    "Program calculates ways to partition array into subsets with specific sum"
  ],
  "editors_take": null,
  "opinion": false,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "machine_translated": false,
  "ai_generated": true,
  "disclaimer": "Accounts, briefs, key points, the editor’s take and translations are written by software from other outlets’ reporting and may contain errors. A summary whose summary_source is \"publisher\" is the outlet’s own feed text. Always check the linked original."
}