This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "friend.h"
using namespace std;
#define ll long long
#define pi pair<int, int>
#define f first
#define s second
#define pb push_back
int findSample(int n, int* confidence, int* host, int* protocol){
int host_v = confidence[n-1], mv = 0, ans = 0;
for(int i = n-1; i; i--){
host_v = confidence[i];
mv = confidence[host[i]];
if(protocol[i] == 0){
if(host_v > mv){
ans += host_v; confidence[host[i]] = 0;
}
else{
ans += host_v; confidence[host[i]] -= host_v;
}
}
else if(protocol[i] == 1){
confidence[host[i]] += host_v;
}
else{
confidence[host[i]] = max(host_v, mv);
}
}
ans += confidence[0];
return ans;
}
/*
int confidence[101], host[101], protocol[101];
signed main(){
int n; cin >> n;
for(int i = 0; i < n; i++){
cin >> confidence[i];
}
for(int i = 1; i < n; i++){
cin >> host[i] >> protocol[i];
}
cout << findSample(n,confidence,host,protocol) << "\n";
}
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |