Source Code
#include <iostream>
#include <algorithm>
#include <utility>

using namespace std;

int main()
{
    int temp;
    int N, M, K;
    int min;
    cin >> N >> M >> K;
    if (M == 0)
    {
        cout << "NO" << endl;
        return 0;
    }

    for (int i = 0; i < N; i++)
    {

        cin >> min;
        for (int j = 1; j < M; j++)
        {
            cin >> temp;
            if (min == -1)
            {
                min = temp;
            }
            else if (temp != -1 && min > temp)
            {
                min = temp;
            }
        }
        if (min != -1)
        {
            K -= min;
        }
        else
        {
            cout << "NO" << endl;
            return 0;
        }
        if (K < 0)
        {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}
Copy
Omar's Gifts DirtyQWERTY
GNU G++17
42 ms
788 KB
Accepted