Submission #51474

#TimeUsernameProblemLanguageResultExecution timeMemory
51474minhducsun2002Foehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
786 ms7572 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long int llint;

int main()
{
	llint peakCount, shiftCount, upshift, downshift;
    cin >> peakCount >> shiftCount >> upshift >> downshift;
    llint peak[peakCount];
    peak[0] = 0;
    for (llint i = 0 ; i <= peakCount ; i++) cin >> peak[i];
    llint diff[peakCount];
    llint _return = 0;
    diff[0] = 0;
    for (llint i = 1 ; i <= peakCount ; i++)
    {
        diff[i] = peak[i - 1] - peak[i];
        _return += ((diff[i] < 0) ? upshift * diff[i] : downshift * diff[i]);
    };
    while (shiftCount--)
    {
        llint left, right, shift;
        cin >> left >> right >> shift;
        if (left > 0)
        {
            _return -= ((diff[left] < 0) ? upshift * diff[left] : downshift * diff[left]);
            diff[left] -= shift;
            _return += ((diff[left] < 0) ? upshift * diff[left] : downshift * diff[left]);
        };
        if (right < peakCount)
        {
            _return -= ((diff[right + 1] < 0) ? upshift * diff[right + 1] : downshift * diff[right + 1]);
            diff[right + 1] += shift;
            _return += ((diff[right + 1] < 0) ? upshift * diff[right + 1] : downshift * diff[right + 1]);
        };
        cout << _return << endl;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...