K. Video Posts
Input
The first line contains two integers n and k (1≤k≤n≤105). The next line contains n positive integer numbers a1,a2,…,an (1≤ai≤104), where ai is the duration of the i-th video.
Output
If solution exists, print "Yes" in the first line. Print k positive integers s1,s2,…,sk (s1+s2+⋯+sk=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists).
If there is no solution, print a single line "No".
Examples
Input
6 3
3 3 1 4 1 6
Output
Yes
2 3 1
Input
3 3
1 1 1
Output
Yes
1 1 1
Input
3 3
1 1 2
Output
No
Input
3 1
1 10 100
Output
Yes
3
题意:就是看能否均分,是的话就Yes,然后输出可以由几个数组成,不是就No
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<math.h>
#include<map>
#include<string>
using namespace std;
typedef long long ll;
map<int,int>mp;
map<int,int>::iterator it;
ll c[100010],a[101010];
int main()
{
ll n,k,i,j,s=0,ss;
cin>>n>>k;
for(i=0; i<n; i++)
{
cin>>a[i];
s+=a[i];
}
if(s%k)
printf("No\n");
else
{
ss=s/k;
ll e=0,ans=0,p=0;
memset(c,0,sizeof(c));
for(i=0; i<n; i++)
{
ans+=a[i];
p++;
if(ans==ss)
{
c[e++]=p;
ans=0;
p=0;
}
}
//cout<<e<<endl;
if(e==k)
{
cout<<"Yes"<<endl;
cout<<c[0];
for(i=1; i<e; i++)
cout<<" "<<c[i];
cout<<endl;
}
else
cout<<"No"<<endl;
}
return 0;
}
D. Garbage Disposal
Examples
Input
3 2
3 2 1
Output
3