这是一道比较水的题目,数据规模很小,先排序,再遍历
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int NODE = 20;
const int INF = 100000000;
int n, b, h, w;
struct Node {
int money;
int week[NODE];
}H[NODE];
bool cmp ( Node a, Node b ) {
return a.money < b.money;
}
int main()
{
while ( scanf("%d%d%d%d", &n, &b, &h, &w) == 4 ) {
for ( int i = 0; i < h; ++i ) {
scanf("%d", &H[i].money);
for ( int j = 0; j < w; ++j ) scanf("%d", &H[i].week[j]);
}
sort( H, H+h, cmp );
int ans = INF, tmp;
for ( int i = 0; i < h; ++i ) {
tmp = n*H[i].money;
if ( tmp > b ) break;
for ( int j = 0; j < w; ++j ) if ( H[i].week[j] >= n ) {
ans = tmp;
break;
}
if ( ans != INF ) break;
}
if ( ans == INF ) printf("stay home\n");
else printf("%d\n", ans);
}
}