Submission
Status:
[PP-SSSSSSSSSS]
Score: 0
User: Pera
Problemset: ซื้อขายหุ้นซีเค
Language: cpp
Time: 0.002 second
Submitted On: 2025-03-27 09:10:49
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n; cin >> n;
vector<int> prices(n);
for (int i = 0; i < n; ++i) cin >> prices[i];
int minPrice = INT_MAX;
int currprofit;
int maxprofit = 0;
for (int i = 0; i < n; ++i) {
currprofit = prices[i] - minPrice;
minPrice = min(minPrice, prices[i]);
maxprofit = max(maxprofit, currprofit);
}
cout << maxprofit << '\n';
}