이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define all(x) x.begin(), x.end()
#define endl '\n'
const int N=200005;
const int INF=1e5;
int32_t main() {
LCBorz;
int n;cin>>n;
vector<int> h(n+2),g[n+1],no(n+2,INF);
vector<vector<int>> v(n+1,vector<int>(n+2)),dp(n+1,vector<int>(n+2,INF));
for(int i=1;i<=n;i++){
cin>>h[i];h[i]=n-h[i];
}
int m;cin>>m;
for(int i=1;i<=m;i++){
int a,b,c;cin>>a>>b>>c;
b=n-b+1;
v[a][b]=c;
g[a].push_back(b);
}
no[0]=0;
dp[0][0]=0;
for(int i=1;i<=n;i++){
int total=0;
for(int j:g[i]){
total+=v[i][j];
}
for(int j=1;j<=h[i];j++){
dp[i][j]=min(dp[i][j],no[i-1]+total-v[i][j]);
if(!v[i][j])dp[i][j]=min(dp[i][j],dp[i-1][j]+total-v[i][j]);
if(j<=h[i]){
for(int k=1;k<=h[i-1];k++){
if(k>h[i]){
dp[i][j]=min(dp[i][j],dp[i-1][k]+total-v[i][j]);
}
else if(j>h[i-1]){
dp[i][k]=min(dp[i][k],dp[i-1][k]+total-v[i][j]);
}
}
}
}
no[i]=*min_element(dp[i].begin()+h[i+1]+1,dp[i].end());
no[i]=min(no[i],no[i-1]+total);
}
cout<<min(*min_element(all(dp[n])),no[n])<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |