Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: erng

Problemset: Fool's Compensation

Language: cpp

Time: 0.002 second

Submitted On: 2026-03-11 16:07:27

#include <bits/stdc++.h>

using namespace std;

#define ll long long

const ll nx=1e4+5;

ll n, arr[nx], cnt[nx], ans;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n;
    for (int i=1; i<=n; i++) cin>>arr[i];
    for (int i=1; i<=n; i++)
    {
        if (i==1 || arr[i]<arr[i-1]) cnt[i]=1;
        else if (arr[i]==arr[i-1]) cnt[i]=cnt[i-1];
        else cnt[i]=cnt[i-1]+1; // this case when arr[i]>arr[i+1]
    }
    // this only satisfies one side (only to the left), how to make it satisfies both side?
    for (int i=n; i>=1; i--)
    {
        if (i==n && arr[i]<arr[i-1]) cnt[i]=1;
        else if (arr[i]>arr[i+1] && cnt[i]<=cnt[i+1]) cnt[i]=cnt[i+1]+1;
        else if (arr[i]==arr[i+1]) cnt[i]=cnt[i+1];
    }
    for (int i=1; i<=n;i++) ans+=cnt[i];
    cout<<ans*1000;
}