B. Video Posts
Polycarp took n n n videos, the duration of the i i i-th video is a i a_i ai seconds. The videos are listed in the chronological order, i.e. the 1 1 1-st video is the earliest, the 2 2 2-nd video is the next, …, the n n n-th video is the last.
Now Polycarp wants to publish exactly k k k ( 1 ≤ k ≤ n 1 \le k \le n 1≤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 j j j-th post is s j s_j sj then:
- s 1 + s 2 + ⋯ + s k = n s_1+s_2+\dots+s_k=n s1+s2+⋯+sk=n ( s i > 0 s_i>0 si>0),
- the first post contains the videos: 1 , 2 , … , s 1 1, 2, \dots, s_1 1,2,…,s1;
- the second post contains the videos: s 1 + 1 , s 1 + 2 , … , s 1 + s 2 s_1+1, s_1+2, \dots, s_1+s_2 s1+1,s1+2,…,s1+s2;
- the third post contains the videos: s 1 + s 2 + 1 , s 1 + s 2 + 2 , … , s 1 + s 2 + s 3 s_1+s_2+1, s_1+s_2+2, \dots, s_1+s_2+s_3 s1+s2+1,s1+s2+2,…,s1+s2+s3;
- …
- the k k k-th post contains videos: n − s k + 1 , n − s k + 2 , … , n n-s_k+1,n-s_k+2,\dots,n n−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 s 1 , s 2 , … , s k s_1, s_2, \dots, s_k s1,s2,…,sk that satisfy all the conditions above.
Input
The first line contains two integers n n n and k k k ( 1 ≤ k ≤ n ≤ 1 0 5 1 \le k \le n \le 10^5 1≤k≤n≤105). The next line contains n n n positive integer numbers a 1 , a 2 , … , a n a_1, a_2, \dots, a_n a1,a2,…,an ( 1 ≤ a i ≤ 1 0 4 1 \le a_i \le 10^4 1≤ai≤104), where a i a_i ai is the duration of the i i i-th video.
Output
If solution exists, print “Yes” in the first line. Print k k k positive integers s 1 , s 2 , … , s k s_1, s_2, \dots, s_k s1,s2,…,sk ( s 1 + s 2 + ⋯ + s k = n s_1+s_2+\dots+s_k=n 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”.
Example
Input
6 3
3 3 1 4 1 6
Output
Yes
2 3 1
Input
3 1
1 10 100
Output
No
code
#include<bits/stdc++.h>
#define int long long
#define endl '\n'using namespace std;const int N = 2e5+10,INF=0x3f3f3f3f,mod=1e9+7;typedef pair<int,int> PII;int T=1;void solve(){int n,k;cin>>n>>k;int sum=0;vector<int> a(n+5,0);vector<int> ans(n+5,0);for(int i=1;i<=n;i++){cin>>a[i];sum+=a[i];}if(sum%k!=0){cout<<"No"<<endl;return;}int x = sum/k;int cnt=0;int t=0;int u=0;for(int i=1;i<=n;i++){if(t+a[i]<x){cnt++;t+=a[i];}else if(t+a[i]==x){cnt++;ans[u++]=cnt;cnt=0;t=0;}else if(t+a[i]>x){cout<<"No"<<endl;return;}}cout<<"Yes"<<endl;for(int i=0;i<u;i++) cout<<ans[i]<<" ";
}signed main(){
// cin>>T; while(T--){solve();}return 0;
}