안녕하세요. 오늘은 호텔을 예약할 거에요.

문제

https://www.acmicpc.net/problem/5046

아이디어

어떤 호텔이 N명을 다 수용할 수 있는 주가 있다면 후보에 듭니다. 그 후보들중 cost가 가장 작은 호텔의 cost값 *N이 B를 넘지 않으면 됩니다.

소스코드

#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;

int main(void)
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll N, B, H, W, i, cost, x, ans = 2e9;
    bool able;

    cin >> N >> B >> H >> W;
    for (i = 0; i < H; i++)
    {
        cin >> cost;
        able = false;
        for (ll j = 0; j < W; j++)
        {
            cin >> x;
            if (x >= N) able = true; //가능
        }
        if (able) ans=min(ans, cost);
    }
    if (ans == 2e9) cout << "stay home";
    else
    {
        if (ans * N <= B) cout << ans * N;
        else cout << "stay home";
    }
}


감사합니다.

0개의 댓글