
BOJ - Best Chance 31800
·
코딩테스트
해결방법핵심은 기회비용을 어떻게 구하느냐에 달린 문제이다. 자기 자신을 제외하고 가장 큰 이익에서 자신의 비용을 제외한 것이 기회비용이므로, 먼저 가장 큰 이익 2개를 구해준다면 문제를 푸는 속도가 빨라지게 된다. 정답 코드#include #include #include using namespace std;int main(){ int N, max1 = -1, max2 = -1; cin >> N; vector Profit(N), Price(N), Alt(N), Net(N); for (int i = 0; i > Profit[i]; for (int i = 0; i > Price[i]; for (int i = 0; i max1) { max2 = max1; ..