※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 14011번 문제인 Small PhD Restaurant이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/14011
14011번: Small PhD Restaurant
"There is probably a place where all waiters have a PhD in, I don't know, some stuff." - Dudu, 2014 Note: This problem is identical to Large PhD Restaurant, but with smaller bounds. Dudu is hungry. He sat down in a nice Thai restaurant. To his amazement,
www.acmicpc.net
14012번 문제에서 N의 제한이 작아진 문제이다. 풀이는 같으므로 해당 글을 참고하자.
N이 작으므로, "도전할 수 있지만 아직 시도하지 않은 이득을 보는 도전"이 더 이상 남지 않을 때까지 반복문을 이용해 각 도전을 살피는 것으로도 해결할 수 있을 것이다.
아래는 제출한 소스코드이다.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
ll arr[1001];
vector<pair<ll, ll>> vec;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N; ll M; cin >> N >> M;
for (int i = 0; i < N; i++) cin >> arr[i];
for (int i = 0; i < N; i++) {
ll x; cin >> x;
if (arr[i] < x) vec.emplace_back(make_pair(arr[i], x - arr[i]));
}
sort(vec.begin(), vec.end());
for (auto p : vec) {
if (p.first <= M) M += p.second;
}
cout << M;
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 24883 // C++] 자동완성 (0) | 2022.05.15 |
---|---|
[BOJ 2961 // C++] 도영이가 만든 맛있는 음식 (0) | 2022.05.15 |
[BOJ 14012 // C++] Large PhD Restaurant (0) | 2022.05.14 |
[BOJ 14009 // C++] Large Weird Measurements (0) | 2022.05.13 |
[BOJ 14007 // C++] Small Weird Measurements (0) | 2022.05.13 |