Submission

Status:

PPPPPP--P-

Subtask/Task Score:

70/100

Score: 70

User: theem1502

Problemset: Fool's Compensation

Language: cpp

Time: 0.033 second

Submitted On: 2026-02-27 22:48:45

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

int main() {
    int num;
    cin >> num;
    vector<int> thearray(num);
    priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> theq;
    for (int i = 0; i < num; i++) {
        cin >> thearray[i];
        theq.push({thearray[i], i});
    }
    vector<int>  visited(num, -1);




    while(!theq.empty()) {
    int thenum = 2;
        int first = theq.top().first, second = theq.top().second;
       // cout << "first = " << first << "\n";
        theq.pop();

        visited[second] = max(1, visited[second]);
        int counter = 1;
        while(second + counter < num && thearray[second + counter] >= thearray[second + counter - 1])
         {


            if (thearray[second + counter] == thearray[second + counter - 1]) {
                 visited[second + counter] = max(thenum - 1, visited[second + counter] );
                 counter++;
                 continue;

            }

            visited[second+ counter] = max(thenum, visited[second + counter] );
           //cout << "debufdg " << second + counter << " " << visited[second + counter] << "\n";
            here:
            counter++;
            thenum++;
         }

          counter = -1;
          thenum = 2;
            while(second + counter >= 0 && thearray[second + counter] >= thearray[second + counter + 1])
         {

            if (thearray[second + counter] == thearray[second + counter + 1]) {
                 visited[second + counter] = max(thenum - 1, visited[second + counter]);
                 counter--;
                 continue;

            }

            visited[second+ counter] = max(thenum, visited[second + counter]);
                     //   cout << "debug " << second + counter << " " << visited[second + counter] << "\n";
                        there:
            counter--;
            thenum++;
         }

    }

    for (int i = 1; i < num ; i++) {
        if (thearray[i] == thearray[i-1]) {
            int temp = max(visited[i], visited[i-1]);
            visited[i] = temp;
            visited[i-1] = temp;

        }

    }

int sum = 0;
    for (int i = 0; i < num; i++) {
       //    cout << visited[i] << " ";
        sum += visited[i];
    }
    cout << 1000 * sum;

}