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 "meetings.h"
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
const int N = 3e5+5;
const ll INF = 1e18+5;
const int MOD = 1e9+7;
vector<long long> minimum_costs(vector<int> arr, vector<int> L, vector<int> R) {
int n = arr.size();
int q = L.size();
int i,j,k;
vector<ll> ans(q);
for(k=0;k<q;k++){
int x = L[k];
int y = R[k];
ll res = INF;
for(i=x;i<=y;i++){
// good i is always local minima
if(i-1 >= 0 && arr[i-1] < arr[i])continue;
if(i+1 < n && arr[i+1] < arr[i])continue;
ll curr = 0;
int maxi = 0;
for(j=i;j<=y;j++){
maxi = max(maxi,arr[j]);
curr += maxi;
}
maxi = arr[i];
for(j=i-1;j>=x;j--){
maxi = max(maxi,arr[j]);
curr += maxi;
}
res = min(res,curr);
}
ans[k] = res;
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |