Source Code
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <deque>
#include <set>

using namespace std;

#define speedup ios::sync_with_stdio(0),cin.tie(0);


int main()
{
    speedup;

    int n,m,k,h;
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)
    {
        vector<int>a;
        for(int j=0;j<m;j++)
        {
            cin>>h;
            if(h!=-1)
            {
                a.push_back(h);
            }
        }
        if(a.size()==0)
        {
            cout<<"NO"<<endl;
            return 0;
        }
        int mn=a[0];
        for(int i=1;i<a.size();i++)
        {
            if(a[i]<mn)
            {
                mn=a[i];
            }
        }
        k=k-mn;
        if(k<0)
        {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;

    return 0;
}
Copy
Omar's Gifts maenobaid
GNU G++17
29 ms
888 KB
Accepted