### Saratov State University :: Online Contester

::Go
- home
- news
- register
 - update personal info
 - problemset archive
- submit
- status online
- standing
- contests
- virtual contests
- forum
- statistic
- FAQ
- projects

 ::Poll Are you registered on Codeforces?YesNoWhat is it???[results]

::webboard

 Why WA on test 15?
Author: Criminal_Leopard
ID: 062859
Problem: 546
Contest: 0
Date: 2014-10-21 17:04:25

Here is my code in c++;

#include<iostream>
using namespace std;

typedef pair<int,int>pii;

const int maxn=210;
int d[3],e[3],n,a,b,ans[maxn],counter=0;
string p;

pii f(int x)
{
if(x==0)
return pii(1,2);
if(x==1)
return pii(0,2);
return pii(0,1);
}

int main()
{
cin>>n>>a>>b>>p;
e[0]=a;
e[1]=b;
e[2]=n-a-b;
int s=p.size();
for(int i=0;i<p.size();i++)
{
ans[i]=p[i]-48;
d[ans[i]]++;
}
for(int i=0;i<s;i++)
{
pii k=f(ans[i]);
if(d[ans[i]]>e[ans[i]])
{
if(d[k.first]<e[k.first])
{
d[k.first]++;
d[ans[i]]--;
ans[i]=k.first;
counter++;
}
else if(d[k.second]<e[k.second])
{
d[k.second]++;
d[ans[i]]--;
ans[i]=k.second;
counter++;
}
else
{
cout<<"-1n";
return 0;
}
}
}
cout<<counter<<endl;
for(int i=0;i<s;i++)
cout<<ans[i];
cout<<endl;
}