Submission

Status:

[PPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: Chawin

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

Language: cpp

Time: 0.012 second

Submitted On: 2026-02-28 20:56:33

#include<bits/stdc++.h>
using namespace std;

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

    int n;
    cin >> n;

    vector<long long> p(n);
    for(int i = 0; i < n; i++){
       cin >> p[i];
    }

    long long profit = 0;
    for(int i = 1; i < n; i++){
        if(p[i] > p[i-1]){
            profit += (p[i] - p[i-1]);
        }
    }

    cout << profit;

    return 0;
}