Submission

Status:

[PPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: Shangbin

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

Language: cpp

Time: 0.009 second

Submitted On: 2026-03-10 10:18:51

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

#define int long long

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

signed 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 = 0; i <= n; i++){
        if (diff[i] > 0) max_profit += diff[i];
    }
    cout << max_profit;
}