※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 13238번 문제인 Bitcoin investment이다.
문제는 아래 링크를 확인하자.

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

 

13238번: Bitcoin investment

Bitcoin is a digital asset and a payment system invented by Satoshi Nakamoto.  It is not known whether the name "Satoshi Nakamoto" is real or a pseudonym, or whether the name represents one person or a group of people. It was once rumoured by New Yorker M

www.acmicpc.net

각 i번째 날에 비트코인을 판매할 때 얻을 수 있는 최대 수익은 (i번째 날의 비트코인의 가격) - (첫번째 날부터 i번째 날까지의 비트코인의 최저가)로 계산할 수 있다.

 

첫번째 날부터 이전 날까지의 비트코인의 최저가를 계속 갱신해나가면서 문제를 해결하자.

 

아래는 제출한 소스코드이다.

#include <iostream>
using namespace std;

int N;
int mn = 1000000007;
int ans = 0;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> N;
	while (N--) {
		int x; cin >> x;
		mn = min(mn, x);
		ans = max(ans, x - mn);
	}

	cout << ans;
}
728x90

'BOJ' 카테고리의 다른 글

[BOJ 13237 // C++] Binary tree  (0) 2023.06.11
[BOJ 4158 // C++] CD  (0) 2023.06.10
[BOJ 13239 // C++] Combinations  (0) 2023.06.08
[BOJ 13215 // C++] Fish  (0) 2023.06.07
[BOJ 13214 // C++] Swaps  (1) 2023.06.06

+ Recent posts