Codeforces 489C. Given Length and Sum of Digits... Solution
Solution in C++:
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include<iostream>
using namespace std;
int main()
{
int m,s,i,j;
cin>>m>>s;
if(s==0)
{
if(m==1)
{
cout<<"0 0"<<endl;
return 0;
}
else
{
cout<<"-1 -1"<<endl;
return 0;
}
}
string mx,mn;
for(i=0; i<m; i++)
{
int v=min(9,s);
mx.push_back('0'+v);
s=s-v;
}
if(s>0)
{
cout<<"-1 -1"<<endl;
return 0;
}
for(i=m-1; i>=0; i--)
{
mn.push_back(mx[i]);
}
j=0;
while(mn[j]=='0')
j++;
mn[0]++;
mn[j]--;
cout<<mn<<" "<<mx<<endl;
}
No comments