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;
#define ll long long
#define fo(i, n) for(ll i = 0; i<(n); i++)
#define pb push_back
#define F first
#define S second
#define deb(x) cout << #x << " = " << (x) << endl
#define deb2(x, y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
typedef vector<ll> vl;
typedef vector<vl> vvl;
vl v;
struct Node{
Node *lnode, *rnode;
ll l, r;
Node(ll l, ll r) : l(l), r(r){
if(r-l==1){
}else{
}
}
};
ll rec(ll lo, ll hi){
if(hi-lo<=0) return 0;
if(hi-lo<=1) return v[lo];
ll maxval = 0;
for(int i = lo; i<hi; i++){
maxval= max(maxval, v[i]);
}
vl temp = {lo-1};
for(int i = lo; i<hi; i++){
if(v[i] == maxval) temp.pb(i);
}
temp.pb(hi);
ll ans = 1e18;
fo(i, ((ll)temp.size())-1){
ans = min(ans, (hi-lo-(temp[i+1]-temp[i]-1ll))*maxval+rec(temp[i]+1, temp[i+1]));
}
// deb2(lo, hi);
// deb(ans);
return ans;
}
vector<long long> minimum_costs(vector<int> H, vector<int> L, vector<int> R) {
int q = L.size();
ll n = H.size();
vl C;
// fo(i, n) v.pb(H[i]);
// Node st(0, n);
fo(i, q){
v.clear();
for(ll j = L[i]; j<=R[i]; j++){
v.pb(H[j]);
}
C.pb(rec(0, v.size()));
}
return C;
}
Compilation message (stderr)
meetings.cpp: In function 'std::vector<long long int> minimum_costs(std::vector<int>, std::vector<int>, std::vector<int>)':
meetings.cpp:56:8: warning: unused variable 'n' [-Wunused-variable]
56 | ll n = H.size();
| ^
# | 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... |