Submission

Status:
[PPPPPPPP-S]

Score: 0

User: Pera

Problemset: stock

Language: cpp

Time: 0.012 second

Submitted On: 2025-03-26 10:10:35

#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 = INT_MIN;

    for (int i = 0; i < n; ++i) {
        currprofit = prices[i] - minPrice;
        minPrice = min(minPrice, prices[i]);
        maxprofit = max(maxprofit, currprofit);
    }

    cout << maxprofit << '\n';
}