Submission #1020618

#TimeUsernameProblemLanguageResultExecution timeMemory
1020618pccFireworks (APIO16_fireworks)C++17
7 / 100
4 ms7672 KiB
#include <bits/stdc++.h> using namespace std; #define pii pair<int,int> #define fs first #define sc second #define ll long long const int mxn = 3e5+10; int N,M; vector<pii> tree[mxn]; int par[mxn]; int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>N>>M; for(int i = 2;i<=N+M;i++){ int p,c; cin>>p>>c; par[i] = p; tree[p].push_back(pii(i,c)); } sort(tree[1].begin(),tree[1].end(),[](pii a,pii b){return a.sc<b.sc;}); int tar = tree[1][tree[1].size()>>1].sc; ll ans = 0; for(auto &i:tree[1])ans += abs(tar-i.sc); cout<<ans<<'\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...