n, k = map(int, input().split())
durations = list(map(int, input().split()))
dsum = sum(durations)
segmentsum = dsum / k
runningtotal = 0
segmentsize = 0
numsegments = 0
output = "Yes"
sizes = []
for i, duration in enumerate(durations):
runningtotal += duration
segmentsize += 1
if runningtotal > segmentsum:
output = "No"
break
elif runningtotal == segmentsum:
runningtotal = 0
numsegments += 1
sizes.append(segmentsize)
segmentsize = 0
if output == "Yes" and runningtotal == 0 and numsegments == k:
print("Yes")
for size in sizes[:-1]:
print(size, end=" ")
print(sizes[-1])
else:
print("No")
#include<bits/stdc++.h>
using namespace std;
//
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define ll long long
#define mod 1000000007
#define mp make_pair
#define flash ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define cinv(a) for(int i=0;i<a.size();i++){ cin>>a[i];}
#define coutv(a) for(int i=0;i<a.size();i++){cout<<a[i]<<" ";}
void solve() {
int n,k;
cin>>n>>k;
vector<int> a(n);
cinv(a);
int sum=0;
for(int i=0;i<n;i++){
sum+=a[i];
}
if(sum%k==0){
bool f=true;
int index=0;
int tempsum=0;
sum=sum/k;
vector<int> ans;
int counts=0;
while(index<n){
tempsum+=a[index];
counts++;
if(tempsum==sum){
tempsum=0;
ans.push_back(counts);
counts=0;
}
else if(tempsum>sum){
f=false;
break;
}
index++;
}
if(f){
cout<<"Yes"<<endl;
for(int i=0;i<k;i++){
cout<<ans[i]<<" ";
}
cout<<"\n";
}
else{
cout<<"No"<<endl;
}
}
else{
cout<<"No"<<endl;
return ;
}
}
int main(){
flash
int tc;
tc=1;
while(tc--){
solve();
}
return 0;
}
1350A - Orac and Factors | 1373A - Donut Shops |
26A - Almost Prime | 1656E - Equal Tree Sums |
1656B - Subtract Operation | 1656A - Good Pairs |
1367A - Short Substrings | 87A - Trains |
664A - Complicated GCD | 1635D - Infinite Set |
1462A - Favorite Sequence | 1445B - Elimination |
1656C - Make Equal With Mod | 567A - Lineland Mail |
1553A - Digits Sum | 1359B - New Theatre Square |
766A - Mahmoud and Longest Uncommon Subsequence | 701B - Cells Not Under Attack |
702A - Maximum Increase | 1656D - K-good |
1426A - Floor Number | 876A - Trip For Meal |
1326B - Maximums | 1635C - Differential Sorting |
961A - Tetris | 1635B - Avoid Local Maximums |
20A - BerOS file system | 1637A - Sorting Parts |
509A - Maximum in Table | 1647C - Madoka and Childish Pranks |