<p>You are given an integer array <code>jobs</code>, where <code>jobs[i]</code> is the amount of time it takes to complete the <code>i<sup>th</sup></code> job.</p>

<p>There are <code>k</code> workers that you can assign jobs to. Each job should be assigned to <strong>exactly</strong> one worker. The <strong>working time</strong> of a worker is the sum of the time it takes to complete all jobs assigned to them. Your goal is to devise an optimal assignment such that the <strong>maximum working time</strong> of any worker is <strong>minimized</strong>.</p>

<p><em>Return the <strong>minimum</strong> possible <strong>maximum working time</strong> of any assignment. </em></p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> jobs = [3,2,3], k = 3
<strong>Output:</strong> 3
<strong>Explanation:</strong> By assigning each person one job, the maximum time is 3.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> jobs = [1,2,4,7,8], k = 2
<strong>Output:</strong> 11
<strong>Explanation:</strong> Assign the jobs the following way:
Worker 1: 1, 2, 8 (working time = 1 + 2 + 8 = 11)
Worker 2: 4, 7 (working time = 4 + 7 = 11)
The maximum working time is 11.</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= k &lt;= jobs.length &lt;= 12</code></li>
	<li><code>1 &lt;= jobs[i] &lt;= 10<sup>7</sup></code></li>
</ul>

static const int _ = [](){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return 0;
}();
class Solution {
public:
    int minimumTimeRequired(vector<int>& jobs, int K) {
        int n=jobs.size();
        int mex=(1<<n)-1;
        int dp[1<<n][K+1];
        memset(dp,-1,sizeof(dp));
        auto get=[&](auto&& get,int mask,int i)->int{
            if(i>=K || mask==mex)return 0;
            if(dp[mask][i]!=-1)return dp[mask][i];
            int ans=2e8;
            if(i==(K-1)){
                int s=0;
                for(int k=0;k<n;k++){
                    if( (mask&(1<<k))==0){
                        s+=jobs[k];  
                    }
                }
                return dp[mask][i]=s;
            }
            vector<pair<int,int>> vi;
            for(int k=0;k<n;k++){
                if((mask&(1<<k))==0)vi.push_back({jobs[k],k});
            }
            int mx=(1<<vi.size())-1;
            for(int j=0;j<=mx;j++){
                    int temp=mask;
                    int s=0;
                    for(int k=0;k<vi.size();k++){
                        if( (j&(1<<k))==0){
                            s+=vi[k].first;
                            temp|=(1<<vi[k].second);
                        }
                    }
                    if(s>0){
                        ans=min(ans,max(s,get(get,temp,i+1)));
                    }
            }
            return dp[mask][i]=ans;
        };
        return get(get,0,0);
    }
};
55770