# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
253226 | 2020-07-27T13:52:34 Z | aZvezda | Friend (IOI14_friend) | C++14 | 0 ms | 0 KB |
#include "friend.h" // Find out best sample const int MAX_N = 1e6 + 10; int dp[MAX_N]; int findSample(int n, int confidence[], int host[], int protocol[]){ for(int i = 0; i < n; i ++) { dp[i] = confidence[i]; } for(int i = n - 1; i > 0; i --) { if(protocol[i] == 1) { dp[host[i]] -= min(dp[i], dp[host[i]]) ans += dp[i]; } else if(protocol[i] == 2) { dp[host[i]] += dp[i]; } else { if(dp[i] > dp[host[i]]) { dp[host[i]] = dp[i]; } } } return ans + dp[0]; }