C++ || EASY TO UNDERSTAND || O(n) complexity || Greedy
\nclass Solution {\npublic:\n    vector<vector<int>> reconstructMatrix(int upper, int lower, vector<int>& colsum) {\n        int m=colsum.size();\n        vecto
```\nclass Solution {\npublic:\n    vector<vector<int>> reconstructMatrix(int upper, int lower, vector<int>& colsum) {\n        int m=colsum.size();\n        vector<vector<int> > ans(2,vector<int>(m));\n        int total=accumulate(colsum.begin(),colsum.end(),0);\n        if(total!=upper+lower)\n        {\n            return {};\n        }\n    \n            for(int j=0;j<m;j++)\n            {\n                if(colsum[j]==2)\n                {\n                    ans[0][j]=1;\n                    ans[1][j]=1;\n                    upper--;\n                    lower--;\n                }\n                else if(colsum[j]==1)\n                {\n                    if(upper>lower)\n                    {\n                      ans[0][j]=1;\n                      upper--;\n                    }\n                    else\n                    {\n                        ans[1][j]=1;\n                        lower--;\n                    }\n                }    \n            }\n        if(upper!=0||lower!=0)\n        return {};\n        return ans;\n    }\n};\n```
[]