#include <bits/stdc++.h>
using namespace std;
#define int long long
#define chmin(a,b) a=(a<b?a:b)
#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=1e18;
int32_t main() {
LCBorz;
int n;cin>>n;
vector<int> h(n+2),g[n+1];
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);
}
dp[0][n+1]=0;
for(int i=1;i<=n;i++){
for(int j=h[i]+1;j<=n;j++){
chmin(dp[i-1][n+1],dp[i-1][j]);
}
int total=0;
for(int j:g[i]){
total+=v[i][j];
}
for(int j=1;j<=n+1;j++){
chmin(dp[i][j],dp[i-1][j]+total);
}
int mn=dp[i-1][n+1];
for(int j=n;j>=1;j--){
chmin(dp[i][j],mn+total-v[i][j]);
chmin(mn,dp[i-1][j]);
}
for(int j=h[i]+1;j<=n+1;j++){
chmin(dp[i][h[i]],mn+total-v[i][j]);
}
for(int j=n;j>=1;j--){
chmin(dp[i][j],dp[i][j+1]);
}
}
cout<<*min_element(all(dp[n]))<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
1880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
1880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
1880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |