// Hi, I'm Yanzhan. I'm interested in all kinds of algorithmic problems. Also, I'm fascinated with javascript. If you want to learn more about programming problems and javascript, please visit my Youtube Channel (https://www.youtube.com/channel/UCDkz-__gl3frqLexukpG0DA?view_as=subscriber), Twitter Account (https://twitter.com/YangYanzhan), GitHub Repo (https://github.com/yangyanzhan/code-camp) or HomePage (https://yanzhan.site/).

// 开始分析
// 1. 贪心。
// 结束分析

// 开始编码

/**
 * @param {number[]} rowSum
 * @param {number[]} colSum
 * @return {number[][]}
 */

var restoreMatrix = function(rowSum, colSum) {
    var m = rowSum.length;
    var n = colSum.length;
    var res = [];
    for (var i = 0; i < m; i++) {
        var row = [];
        for (var j = 0; j < n; j++) {
            var num = Math.min(rowSum[i], colSum[j]);
            row.push(num);
            rowSum[i] -= num;
            colSum[j] -= num;
        }
        res.push(row);
    }
    return res;
};
