Video Posts
Polycarp took nnn videos, the duration of the iii-th video is aia_iai seconds. The videos are listed in the chronological order, i.e. the 111-st video is the earliest, the 222-nd video is the next, …
B. Video Posts
Problem
Polycarp took nnn videos, the duration of the iii-th video is aia_iai seconds. The videos are listed in the chronological order, i.e. the 111-st video is the earliest, the 222-nd video is the next, …, the nnn-th video is the last.
Now Polycarp wants to publish exactly kkk (1≤k≤n1 \le k \le n1≤k≤n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the jjj-th post is sjs_jsj then:
- s1+s2+⋯+sk=ns_1+s_2+\dots+s_k=ns1+s2+⋯+sk=n (KaTeX parse error: Expected 'EOF', got '&' at position 4: s_i&̲gt;0),
- the first post contains the videos: 1,2,…,s11, 2, \dots, s_11,2,…,s1;
- the second post contains the videos: s1+1,s1+2,…,s1+s2s_1+1, s_1+2, \dots, s_1+s_2s1+1,s1+2,…,s1+s2;
- the third post contains the videos: s1+s2+1,s1+s2+2,…,s1+s2+s3s_1+s_2+1, s_1+s_2+2, \dots, s_1+s_2+s_3s1+s2+1,s1+s2+2,…,s1+s2+s3;
- …
- the kkk-th post contains videos: n−sk+1,n−sk+2,…,nn-s_k+1,n-s_k+2,\dots,nn−sk+1,n−sk+2,…,n.
Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same.
Help Polycarp to find such positive integer values s1,s2,…,sks_1, s_2, \dots, s_ks1,s2,…,sk that satisfy all the conditions above.
Input
The first line contains two integers nnn and kkk (1≤k≤n≤1051 \le k \le n \le 10^51≤k≤n≤105). The next line contains nnn positive integer numbers a1,a2,…,ana_1, a_2, \dots, a_na1,a2,…,an (1≤ai≤1041 \le a_i \le 10^41≤ai≤104), where aia_iai is the duration of the iii-th video.
Output
If solution exists, print “Yes” in the first line. Print kkk positive integers s1,s2,…,sks_1, s_2, \dots, s_ks1,s2,…,sk (s1+s2+⋯+sk=ns_1+s_2+\dots+s_k=ns1+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
Code
// #include <iostream>
// #include <algorithm>
// #include <cstring>
// #include <stack>//栈
// #include <deque>//堆/优先队列
// #include <queue>//队列
// #include <map>//映射
// #include <unordered_map>//哈希表
// #include <vector>//容器,存数组的数,表数组的长度
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+10;
ll a[N],b[N];
void solve()
{
ll n,k;
cin>>n>>k;
for(ll i=1;i<=n;i++)
{
cin>>a[i];
a[i]+=a[i-1];
}
if(a[n]%k)
{
cout<<"No"<<endl;
return;
}
ll res=a[n]/k;
ll sum=res,op=0;
for(ll i=1;i<=n;i++)
{
if(a[i]==sum)
{
b[++op]=i;
sum+=res;
}
}
if(op!=k)
{
cout<<"No"<<endl;
return;
}
cout<<"Yes"<<endl;
for(ll i=1;i<=k;i++) cout<<b[i]-b[i-1]<<" ";
cout<<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
ll t=1;
//cin>>t;
while(t--) solve();
return 0;
}
更多推荐




所有评论(0)