Need help for problem code NOKIA

I’m just starting to learn programming and I was solving the problem whose code is NOKIA for practice. I’ve coded a solution which is almost the same as the editorial for that problem.

#include <iostream>
#include <limits.h>
#include <vector>
#include <set>

using namespace std;

static bool DEBUG = false;

int GIF(double num){ return (num-(int)num)>0.0000?(num+1):num;}

int main()
{
	int cases, n, m, wastedWire, tmp = 0;
	cin>>cases;
	while(cases--)
	{
		cin>>n>>m;
		vector<set<int> > dp(n + 1);
		dp[0].insert(0);
		dp[1].insert(2);
		dp[2].insert(5);
		wastedWire = INT_MAX;
		for(int i = 3; i <= n; ++i)
		{
			if(DEBUG)
				cout<<"For "<<i<<" slots"<<endl;
			int limit = GIF(i/2.0);
			for(int j = 1; j <= limit; ++j)
			{
				tmp = j + (i - j) + 1;
				for(set<int>::iterator k = dp[j - 1].begin(); k != dp[j - 1].end(); ++k)
				{
					for(set<int>::iterator l = dp[i - j].begin(); l != dp[i - j].end(); ++l)
					{
						if(DEBUG)
							cout<<(tmp + *k + *l)<<endl;
						dp[i].insert(tmp + *k + *l);
					}
				}
			}
		}
		for(set<int>::iterator i = dp[n].begin(); i != dp[n].end(); ++i)
		{
			if(wastedWire > (m - *i))
				wastedWire = m - *i;
		}
		if(wastedWire >= 0)
			cout<<wastedWire<<endl;
		else
			cout<<-1<<endl;
	}
}

This solution is wrong and I can’t figure out why. Can anyone help or point me in the right direction? Any help is appreciated because I’ve already pushed myself quite a bit to solve this problem and I can’t think anymore :confused:

//