(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #43916

#TimeUsernameProblemLanguageResultExecution timeMemory
43916YehezkielPaprike (COI18_paprike)C++11
100 / 100
102 ms44092 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define mp make_pair #define eb emplace_back #define pb push_back #define all(x) (x).begin(),(x).end() typedef long long LL; typedef pair<int,int> pii; typedef long double LD; const int MAXN=100000; int n,k,harga[MAXN+5],ans=0; vector <int> node[MAXN+5]; int hitung(int now,int par){ vector <int> temp; LL sum=harga[now]; for(auto v:node[now]) { if(v==par) continue; temp.pb(hitung(v,now)); sum+=temp.back(); } sort(all(temp)); int idx=temp.size()-1; while(sum>(LL) k) { sum-=temp[idx--]; ans++; } return sum; } int main() { scanf("%d%d",&n,&k); for(int i=1;i<=n;i++) scanf("%d",&harga[i]); for(int i=1;i<=n-1;i++) { int u,v; scanf("%d%d",&u,&v); node[u].pb(v); node[v].pb(u); } hitung(1,0); cout<<ans<<endl; }

Compilation message (stderr)

paprike.cpp: In function 'int main()':
paprike.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&k);
  ~~~~~^~~~~~~~~~~~~~
paprike.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&harga[i]);
   ~~~~~^~~~~~~~~~~~~~~~
paprike.cpp:43:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&u,&v);
   ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...