<p>You have observations of <code>n + m</code> <strong>6-sided</strong> dice rolls with each face numbered from <code>1</code> to <code>6</code>. <code>n</code> of the observations went missing, and you only have the observations of <code>m</code> rolls. Fortunately, you have also calculated the <strong>average value</strong> of the <code>n + m</code> rolls.</p>

<p>You are given an integer array <code>rolls</code> of length <code>m</code> where <code>rolls[i]</code> is the value of the <code>i<sup>th</sup></code> observation. You are also given the two integers <code>mean</code> and <code>n</code>.</p>

<p>Return <em>an array of length </em><code>n</code><em> containing the missing observations such that the <strong>average value </strong>of the </em><code>n + m</code><em> rolls is <strong>exactly</strong> </em><code>mean</code>. If there are multiple valid answers, return <em>any of them</em>. If no such array exists, return <em>an empty array</em>.</p>

<p>The <strong>average value</strong> of a set of <code>k</code> numbers is the sum of the numbers divided by <code>k</code>.</p>

<p>Note that <code>mean</code> is an integer, so the sum of the <code>n + m</code> rolls should be divisible by <code>n + m</code>.</p>

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

<pre>
<strong>Input:</strong> rolls = [3,2,4,3], mean = 4, n = 2
<strong>Output:</strong> [6,6]
<strong>Explanation:</strong> The mean of all n + m rolls is (3 + 2 + 4 + 3 + 6 + 6) / 6 = 4.
</pre>

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

<pre>
<strong>Input:</strong> rolls = [1,5,6], mean = 3, n = 4
<strong>Output:</strong> [2,3,2,2]
<strong>Explanation:</strong> The mean of all n + m rolls is (1 + 5 + 6 + 2 + 3 + 2 + 2) / 7 = 3.
</pre>

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

<pre>
<strong>Input:</strong> rolls = [1,2,3,4], mean = 6, n = 4
<strong>Output:</strong> []
<strong>Explanation:</strong> It is impossible for the mean to be 6 no matter what the 4 missing rolls are.
</pre>

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

<ul>
	<li><code>m == rolls.length</code></li>
	<li><code>1 &lt;= n, m &lt;= 10<sup>5</sup></code></li>
	<li><code>1 &lt;= rolls[i], mean &lt;= 6</code></li>
</ul>

class Solution {
public:
    // vector<int>callmeanytime(vector<int>v,int n){
    //     reverse(v.begin(),v.end());
    //     vector<int>nums;
    //     nums.push_back(6);
    //     int number=v[0]-6;
    //     for(int i=1;i<n;i++){
    //         if( number>0 && nums[i-1]+number>6){
    //         nums.push_back(6);
    //         number=number-(6-nums[i-1]);
    //         }
    //         else if( number>0 && nums[i-1]+number <=6){
    //             nums.push_back(nums[i-1]+number);
    //             number=0;
    //         }
    //         else {
    //             nums.push_back(nums[i-1]);
    //         }
    //     }
    //     return nums;
    // }
    vector<int> callme(int n,int key){
        vector<int>v;
        for(int i=0;i<n;i++){
            v.push_back(key);
        }
        return v;
    }
    int sumarray(vector<int>num,int n){
        int sum=0;
        for(int i=0;i<n;i++){
            sum+=num[i];
        }
        return sum;
    }
    vector<int> missingRolls(vector<int>& rolls, int mean, int n) {
        set<int>s;
        int m=rolls.size();
        for(int i=0;i<m;i++){
            s.insert(rolls[i]);
        }
        int setSize=s.size();


        auto it=s.begin();
        if(mean==1 || mean==6){
            if(setSize==1 && *it==1){
                return callme(n,1);
            }
            else if(setSize==1 && *it==6){
                return callme(n,6);
            }
        }
        else {
             int sum=sumarray(rolls,m);
             int x=(n+m)*mean-sum;
             if(x <=0){
               return vector<int>();
             }
             else if(x>0 &&  ceil((float)x/n)>6){
                return vector<int>();
             }
             else if(x>0 &&  x/n==0){
                return vector<int>();
             }  
             else {
                if(x%n==0){
                    int number=x/n;
                    vector<int>v1(n,number);
                    return v1;
                }
                else {
                    int number=x/n;
                    vector<int>v2(n,number);
                     int remainder = x % n;
                    for (int i = 0; i < remainder; i++) {
                    v2[i]++;
                    }
                    return v2;
                }
             }     
        }
        return vector<int>();       
    }
};
78300