Submission

Status:

[PPPP-SSSSSSSS]

Subtask/Task Score:

{0/100}

Score: 0

User: Shangbin

Problemset: ซื้อขายหุ้นซีเค

Language: cpp

Time: 0.008 second

Submitted On: 2026-03-10 10:13:11

//Problem = https://grader.gchan.moe/problemset/c2_st66_stock/statement
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5 + 5;
int n, p[maxn], diff[maxn], max_profit = 0;

int main(){
    cin.tie(nullptr)->sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
        if (i >= 2) diff[i] = p[i] - p[i - 1];
    }
    for (int i = 2; i <= n; i++){
        if (diff[i] > 0) max_profit += diff[i];
    }
    cout << max_profit;
}