Submission #13058217


Source Code Expand

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& STL DEBUGGER &&&&&&&&&&&&&&&&&&&&&&&&&&&

//#define _GLIBCXX_DEBUG       // Iterator safety; out-of-bounds access for Containers, etc.
//#pragma GCC optimize "trapv" // abort() on (signed) integer overflow.

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& LIBRARIES &&&&&&&&&&&&&&&&&&&&&&&&&&&

#include <bits/stdc++.h>
using namespace std;

/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
template<typename T, typename V = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, V, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>; 
*/
// find_by_order(), order_of_key() 

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DEFINES &&&&&&&&&&&&&&&&&&&&&&&&&&&

#define int long long int 
#define ld long double
#define X first
#define Y second
#define all(i) i.begin(), i.end()
#define sz(a) (int)a.size()
 
const ld PI  = 3.141592653589793238463;
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = {-1, 0, 1, 0};
const int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DEBUG &&&&&&&&&&&&&&&&&&&&&&&&&&&
 
#define XOX
vector<string> vec_splitter(string s) {
    for(char& c: s) c = c == ','?  ' ': c;
    stringstream ss; ss << s;
    vector<string> res;
    for(string z; ss >> z; res.push_back(z));
    return res;
}
 
void debug_out(vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
    if(idx > 0) cerr << ", ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, T...);
}
 
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
#else
#define debug(...) 42
#endif
 
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& CODE &&&&&&&&&&&&&&&&&&&&&&&&&&&

int n, m, x;
vector<int> cost;
vector<vector<int>> v;

void solve(){
	cin >> n >> m >> x;
	cost.resize(n);
	v.assign(n, vector<int>(m));
	for(int i = 0; i < n; ++i){
		cin >> cost[i];
		for(int j = 0; j < m; ++j){
			cin >> v[i][j];
		}
	}
	int LIM = (1<<n);
	int mncost = (int)1e18;
	for(int mask = 0; mask < LIM; ++mask){
		vector<int> fin(m, 0);
		int ct = 0;
		for(int i = 0; i < n; ++i){
			if( ((mask>>i)&1) ){
				ct += cost[i];
				for(int j = 0; j < m; ++j){
					fin[j] += v[i][j];
				}
			}
		}
		bool valid = true;
		for(auto &y: fin)
			valid &= (y >= x);
		if(valid){
			mncost = min(mncost, ct);
		}
	}
	if(mncost == (int)1e18){
		cout << -1 << '\n';
		return;
	}
	cout << mncost << '\n';


}

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
    int T = 1; 
    //cin >> T;
    for(int i = 1; i <= T; ++i){
        solve();
    }
    return 0;
}
/*
Sample inp
*/

Submission Info

Submission Time
Task C - Skill Up
User ritik_patel05
Language C++ (GCC 9.2.1)
Score 300
Code Size 3070 Byte
Status AC
Exec Time 3 ms
Memory 3660 KiB

Judge Result

Set Name sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 24
Set Name Test Cases
sample sample01, sample02, sample03
All border01, border02, border03, border04, hand01, hand02, hand03, hand04, hand05, large01, large02, large03, large04, large05, large06, large07, large08, random01, random02, random03, random04, sample01, sample02, sample03
Case Name Status Exec Time Memory
border01 AC 3 ms 3468 KiB
border02 AC 3 ms 3584 KiB
border03 AC 3 ms 3580 KiB
border04 AC 3 ms 3628 KiB
hand01 AC 2 ms 3576 KiB
hand02 AC 1 ms 3560 KiB
hand03 AC 3 ms 3660 KiB
hand04 AC 3 ms 3592 KiB
hand05 AC 3 ms 3564 KiB
large01 AC 3 ms 3512 KiB
large02 AC 3 ms 3512 KiB
large03 AC 3 ms 3528 KiB
large04 AC 3 ms 3616 KiB
large05 AC 3 ms 3584 KiB
large06 AC 3 ms 3584 KiB
large07 AC 3 ms 3508 KiB
large08 AC 3 ms 3628 KiB
random01 AC 2 ms 3524 KiB
random02 AC 3 ms 3624 KiB
random03 AC 3 ms 3596 KiB
random04 AC 2 ms 3656 KiB
sample01 AC 2 ms 3592 KiB
sample02 AC 2 ms 3616 KiB
sample03 AC 2 ms 3520 KiB