Submission

Status:

----------

Subtask/Task Score:

0/100

Score: 0

User: theem1502

Problemset: Fool's Compensation

Language: cpp

Time: 0.005 second

Submitted On: 2026-02-27 22:33:03

#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();
        if (visited[second] != -1) {
            continue;
        }
        visited[second] = 1;
        int counter = 1;
        while(second + counter < num && thearray[second + counter] > thearray[second + counter - 1])
         {
               if (visited[second + counter] != -1) {
            break;
        }

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

            }

            visited[second+ counter] = thenum;
        //    cout << second + counter << "\n";
            here:
            counter++;
            thenum++;
         }

          counter = -1;
          thenum = 2;
            while(second + counter >= 0 && thearray[second + counter] >= thearray[second + counter + 1])
         {
               if (visited[second + counter] != -1) {
            break;
        }
            if (thearray[second + counter] == thearray[second + counter + 1]) {
                 visited[second + counter] = thenum - 1;
                 counter--;
                 continue;

            }

            visited[second+ counter] = thenum;
                //        cout << "debug " << 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;

}