Code Submission Evaluation System Login

CSES - HIIT Open 2018

HIIT Open 2018

Contest start:2018-05-26 11:00:00
Contest end:2018-05-26 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard | Statistics


History
2018-05-26 11:58:21
2018-05-26 11:47:45
Task:Buy Low, Sell High
Sender:TreamDeam
Submission time:2018-05-26 11:58:21
Status:READY
Result:ACCEPTED

Show test data

Code

#include <iostream>

using namespace std;

int main() {
    int le, e;
    cin >> le;

    int l[le] = {0};
    int a[le] = {0};

    for (int i = 0; i < le; i++) {
        cin >> e;
        l[i] = e;
    }


    a[0] = -l[0];
    for (int i = 1; i < le; i++)
     a[i] = max(a[i-1],-l[i]);

    a[0] = 0;
    for (int i = 1; i < le; i++)
     a[i] = max(a[i-1], a[i] + l[i]);

    a[0] = -l[0];
    for (int i = 1; i < le; i++)
     a[i] = max(a[i-1], a[i] - l[i]);

    a[0] = 0;
    for (int i = 1; i < le; i++)
     a[i] = max(a[i-1], a[i] + l[i]);

    cout << a[le - 1] << endl;


    return 0;
}