이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// #include "meetings.h"
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define print(a) for(int i=0;i<a.size();i++)cout<<a[i]<<endl;
using namespace std;
vector<long long> minimum_costs(vector<int> H, vector<int> L,vector<int> R) {
int q = L.size();
int n = H.size();
vector<vector<ll>>prefix(n,vector<ll>(n+1,0));
for(int i=0;i<n;i++){
ll mx=0;
for (int j=i;j<n;j++){
mx=max(mx,(ll)H[j]);
prefix[i][j+1]=prefix[i][j]+mx;
// cout<<prefix[i][j+1]<<" ";
}
// cout<<endl;
}
vector<long long> C(q);
for(int i=0;i<q;i++){
ll mx=0;
ll mn=LONG_LONG_MAX;
vector<ll>maxs(n,0);
for(int j=L[i];j<=R[i];j++){
mx=max(mx,(ll)H[j]);
maxs[j]=mx;
}
// for(int j=0;j<n;j++)cout<<maxs[j]<<' ';cout<<endl;
for(int j=L[i];j<=R[i];j++){
ll sm=0;
// sm+=H[j];
// if(j!=L[i]){
sm+=maxs[j]*(j-L[i]);
// }
sm+=prefix[j][R[i]+1]-prefix[j][j];
mn=min(mn,sm);
}
C[i]=mn;
}
return C;
}
// int main(){
// vector<ll>c;
// c=minimum_costs({2,4,3,5,4}, {0,1,0}, {2,3,4});
// print(c);
// }
# | 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... |