| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 418471 | FlippenFaz | Meetings (IOI18_meetings) | C++11 | 0 ms | 0 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<pair<int,int>> highestNeighs;
ll calc_cost(const vector<ll> &h, int left, int right, int mid) {
    //cout << "CALC " << left << " TO " << right << " USING MID: " << mid << endl; 
    ll sum = -h[mid];
    int temp = mid;
    while (temp <= right) {
        //cout << "TEMP, HIGHEST RIGHT: " << temp << " " << highestNeighs[temp].second << endl;
        //cout << "TEMP HEIGHT: " << h[temp] << endl;
        //cout << "CURSUM: " << sum << endl;
        sum += h[temp] * (min(highestNeighs[temp].second-1, right) - temp+1);
        //cout << "NEW SUM: " << sum << endl;
        temp =  highestNeighs[temp].second;
    }
    temp = mid;
    while (temp >= left) {
        //cout << "TEMP, HIGHEST Left: " << temp << " " << highestNeighs[temp].first << endl;
        //cout << "TEMP HEIGHT: " << h[temp] << endl;
        //cout << "CURSUM: " << sum << endl;
        sum += h[temp] * (temp - max(highestNeighs[temp].first+1, left) + 1);
        //cout << "NEW SUM: " << sum << endl;
        temp =  highestNeighs[temp].first;
    }
    //cout << "GOT: " << sum << endl;
    return sum;
    
}
vector<ll> minimum_costs(vector<ll> h, vector<int> l, vector<int> r) {
    vector<ll> ans;
    
    for (int i = 0; i < h.size(); i++) {
        int left = -1;
        int right = h.size()+1;
        for (int j = i-1; j >= 0; j--) {
            if (h[j] > h[i]) {
                //cout << "HIGHEST LEFT OF " << i << " IS " << j;
                left = j;
                break;
            }
        }
        for (int j = i+1; j < h.size(); j++) {
            if (h[j] > h[i]) {
                right = j;
                break;
            }
        }
        highestNeighs.push_back(make_pair(left, right));
    }
    for (int i = 0; i < l.size(); i++) {
        ll mn = INT64_MAX;
        for (int j = l[i]; j <= r[i]; j++) {
            mn = min(mn, calc_cost(h, l[i], r[i], j));
        }
        ans.push_back(mn);
    }
    return ans;
}
