#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx=2e3+5;
ll n, m, a, b, c, h[nx], dp[nx][nx], sm[nx], res=LLONG_MAX;
vector<pair<ll, ll>> d[nx];
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=1; i<=n; i++) cin>>h[i];
cin>>m;
for (int i=1; i<=m; i++) cin>>a>>b>>c, d[a].push_back({b, c}), sm[a]+=c;
for (int i=1; i<=n; i++)
{
for (int j=0; j<=h[i]; j++) dp[i-1][0]=min(dp[i-1][0], dp[i-1][j]);
for (int j=0; j<=n; j++) dp[i][j]=dp[i-1][j]+sm[i];
for (auto [b, c]:d[i]) dp[i][b]=min(dp[i][b], dp[i-1][0]+sm[i]-c);
}
for (int i=0; i<=n; i++) res=min(res, dp[n][i]);
cout<<res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2312 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2312 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2312 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |