fork download
  1. #include <iostream>
  2. using namespace std;
  3. const int INF = 1e9;
  4.  
  5. int main() {
  6. int n, m, x;
  7. cin >> n >> m >> x;
  8. int c[n];
  9. int a[n][m];
  10.  
  11. for(int i = 0; i < n; i++) {
  12. cin >> c[i];
  13. for(int j = 0; j < m; j++) {
  14. cin >> a[i][j];
  15. }
  16. }
  17.  
  18. int ans = INF;
  19. for(int bit = 0; bit < (1 << n); bit++) {
  20. int understood[m] = {};
  21. int price = 0;
  22. for(int i = 0; i < n; i++) {
  23.  
  24. if((bit >> i) & 1) {
  25. cout << bit << endl;
  26. price += c[i];
  27. for(int j = 0; j < m; j++) {
  28. understood[j] += a[i][j];
  29. }
  30. }
  31. }
  32.  
  33. bool ok = true;
  34. for(int i = 0; i < m; i++) {
  35. if(understood[i] < x) {
  36. ok = false;
  37. break;
  38. }
  39. }
  40.  
  41. // cout << price << ' ' << ok << endl;
  42. if(ok) ans = min(ans, price);
  43. }
  44.  
  45. if(ans == INF) ans = -1;
  46. cout << ans << endl;
  47.  
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0.36s 1265548KB
stdin
Standard input is empty
stdout
-1