끄적끄적 코딩
article thumbnail
Published 2019. 10. 14. 08:20
[C++] 백준 17521번 Byte Coin 알고리즘

투자를 해서 돈을 가장 많이 벌었을 때의 금액을 구하는 문제입니다.

그래프가 내려갈때는 판매를 하고,
올라갈때는 구매를 해서 계산해주면 됩니다.

 

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;

typedef long long ll;

int main(int argc, char* argv[])
{
	ll n, w;
	ll x;
	ll arr[20];

	cin >> n >> w;

	for (int i = 0; i < n; ++i) {
		cin >> arr[i];
	}

	for (int i = 0; i < n - 1; ++i) {

		if (arr[i] < arr[i +1]) {
			x = w / arr[i];
			w = w % arr[i];
			x = arr[i + 1] * x;
			w += x;
		}
	}

	cout << w << endl;

	return 0;
}

 

 

'알고리즘' 카테고리의 다른 글

[C++] 백준 2805번 나무 자르기  (0) 2019.10.15
[C++] 백준 2512번 예산  (0) 2019.10.15
[C++] 백준 17520번 Balanced String  (0) 2019.10.14
[C++] 백준 11378번 열혈강호 4  (0) 2019.10.13
[C++] 백준 11377번 열혈강호 3  (0) 2019.10.13

검색 태그