abc186_b - Blocks On Grid

To make all blocks the same height, make them the same height. as the smallest block.

Time complexity: $O(hw)$

Memory complexity: $O(hw)$

Click to show code.


using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
int main(void)
{
    ios::sync_with_stdio(false), cin.tie(NULL);
    int h, w;
    cin >> h >> w;
    ll minv = 1e9, sum = 0;
    for (int r = 0; r < h; ++r)
    {
        for (int c = 0; c < w; ++c)
        {
            ll arc;
            cin >> arc;
            minv = min(minv, arc);
            sum += arc;
        }
    }
    cout << sum - (h * w * minv) << endl;
    return 0;
}