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 pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ar2 = array<int,2>;
const int INF = (int)1e9;
const ll LINF = (ll)2e18;
const int mxN = (int)5e3+10;
int n, q;
vi a;
ll le[mxN][mxN], ri[mxN][mxN];
vll minimum_costs(vi A, vi L, vi R) {
n = sz(A); q = sz(L); a = A;
for(int i = 0; i < n; i++){
int cur = 0;
for(int j = i; j < n; j++)
cur = max(cur,a[j]), ri[i][j]=(j?ri[i][j-1]:0ll)+(ll)cur;
cur = 0;
for(int j = i; j>=0; j--)
cur = max(cur,a[j]), le[i][j]+=le[i][j+1]+(ll)cur;
}
vll ans(q,LINF);
for(int i = 0; i < q; i++){
int l = L[i], r = R[i];
for(int j = l; j <= r; j++)
ans[i]=min(ans[i],le[j][l]+ri[j][r]-(ll)a[j]);
}
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... |