Submission #960141

#TimeUsernameProblemLanguageResultExecution timeMemory
960141MinaRagy06Fireworks (APIO16_fireworks)C++17
0 / 100
2 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 305; const ll inf = 2e18; vector<array<int, 2>> adj[N]; ll dp[N][N]; int main() { ios_base::sync_with_stdio(0), cin.tie(0); int n, m; cin >> n >> m; n += m; for (int i = 2; i <= n; i++) { int p, c; cin >> p >> c; adj[p].push_back({i, c}); } for (int i = 2; i <= n; i++) { if (adj[i].empty()) { assert(i >= n - m + 1); } } for (int i = n; i >= 1; i--) { for (int j = 0; j < N; j++) { for (auto [nxt, w] : adj[i]) { ll mn = 1e18; for (int k = 0; k <= j; k++) { mn = min(mn, dp[i][j - k] + abs(k - w)); } dp[i][j] += mn; dp[i][j] = min(dp[i][j], inf); } } } cout << *min_element(dp[1], dp[1] + N) << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...