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>
using namespace std;
#define int long long
#define itn int
const int sz = 1e5 + 5;
vector<int> g[sz];
signed main(){
int n,k;
cin >> n >> k;
vector<int> hmm(n+1);
int a,b;
for(int i=1;i<=n;++i)cin >> hmm[i];
for(int i=1;i<n;++i){
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
int cnt=0;
int mink = 0;
int cvb=0;
for(int i=1;i<=n;++i){
cnt += hmm[i];
if(cnt > k){
mink++;
cnt = hmm[i];
}
}
cnt = 0;
for(int i=n;i>0;--i){
cnt += hmm[i];
if(cnt > k){
cvb++;
cnt = hmm[i];
}
}
cout << min(cvb,mink);
}
# | 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... |