Can anyone help me with what test case I am missing ,It is failing at test case 12,which is very large.Please help. Link to submission: http://codeforces.com/contest/551/submission/59558421
#include<bits/stdc++.h>
using namespace std;
vector<int> cnts(26),cnta(26),cntb(26);
int main(){
string s,a,b;
cin>>s>>a>>b;
for(int i=0;i<a.size();i++){
cnta[a[i]-'a']++;
}
for(int j=0;j<b.size();j++){
cntb[b[j]-'a']++;
}
for(int i=0;i<s.size();i++){
cnts[s[i]-'a']++;
}
int mn=INT_MAX;
for(int i=0;i<26;i++){
if(cnta[i]>0){
mn=min(mn,cnts[i]/cnta[i]);
}
}
for(int i=0;i<26;i++){
cnts[i]=cnts[i]-mn*cnta[i];
}
int mn1=INT_MAX;
for(int i=0;i<26;i++){
if(cntb[i]>0){
mn1=min(mn1,cnts[i]/cntb[i]);
}
}
for(int i=0;i<26;i++){
cnts[i]=cnts[i]-mn1*cntb[i];
}
string ans;
while(mn--){
ans+=a;
}
while(mn1--){
ans+=b;
}
for(int i=0;i<26;i++){
if(cnts[i]){
while(cnts[i]--){
ans+='a'+i;
}
}
}
cout<<ans<<endl;
}
Test this.
mztskopjetisisampiosrcenaterenostaviajdezanaspobedi mzt optee
it should be mztopteeopteeopteeaaaaaabcddiiiiijjkmnnnorrssssssvz
MY output : mztmztopteeopteeaaaaaabcddeeiiiiijjknnnooprrssssssv
IN My program is mzt 2 time and in your's 1 time and mine optee 2 time yours 3 time .But both strings are repeated total 4 times in both of our solution I think both should be correct according to the problem? Please correct me if i am wrong.
Sorry I didn't notice it have not only one possible answer, you are right.
Please help bro
I think you should use the shortest string first between B and C. I didn't verificated it because I am not in home, if I arrived in home I'll try it.
I have tried both the ways but still not getting correct answer,I think greedy will not work here