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);

long long int power(long long int n,long long int p)
{
    long long int x=1;
    for(int i=1;i<=p;i++)
    {
        x*=n;
    }
    return x;
}

template<typename t>
t gcd(t a,t b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b,a%b);
}

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 IssamAbdoh
GNU G++17
18 ms
908 KB
Accepted