最近的比赛时间都是什么心态。。。
这题贪心很直观了吧。
显然字母可以分开来考虑。。每次选取该字母需要sticker最多的,+上该字母
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
#include<queue>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN (1000+10)
#define MP(a,b) make_pair(a,b)
long long mul(long long a,long long b){return (a*b)%F;}
long long add(long long a,long long b){return (a+b)%F;}
long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}
typedef long long ll;
typedef pair<int,char> pic;
int n,m;
char s[MAXN],ans[MAXN];
int c[MAXN]={0};
struct node
{
int a,b;
char c;
node(){}
node(int _a,char _c):a(_a),b(1),c(_c){}
int v(){return a/b+(bool)(a%b);}
friend bool operator<(node a,node b){return a.v()<b.v(); }
};
priority_queue< node > h;
int main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
scanf("%s%d",s+1,&m);ans[m+1]=0;n=strlen(s+1);
For(i,n) c[s[i]]++;
for(int i='a';i<='z';i++) if (c[i]) h.push(node(c[i],i)),ans[h.size()]=i;
if (h.size()>m) cout<<"-1"<<endl;
else
{
Fork(i,h.size()+1,m)
{
node p=h.top();
h.pop();
ans[i]=p.c;
p.b++;
h.push(p);
}
node p=h.top();
cout<<p.v()<<endl;
printf("%s\n",ans+1);
}
return 0;
}