-
Notifications
You must be signed in to change notification settings - Fork 0
/
uva11559.cpp
44 lines (40 loc) · 920 Bytes
/
uva11559.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// 11559.cpp
// Author: skmisaac
#include <cstdio>
#include <cstdlib>
#include <algorithm>
int main(int argc, char const *argv[])
{
using namespace std;
int n, b, h, w, p;
int solution = 0;
int cheap = 100000000;
while ( scanf("%d %d %d %d", &n, &b, &h, &w) != EOF ) {
solution = 0; // reset
cheap = 100000000;
for (int i = 0; i < h; ++i)
{
scanf("%d\n", &p);
for (int j = 0; j < w; ++j)
{
int space;
scanf("%d", &space);
if ( space < n || b < n * p ) // not enough space in one hotel OR budget is insufficient
{
continue;
}
else if ( space >= n && b >= n * p )
{
solution = n * p;
if ( solution < cheap )
cheap = solution;
}
}
}
if ( cheap && cheap < 100000000 )
printf("%d\n", cheap);
else
printf("stay home\n");
}
return 0;
}