Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
- #define pb push_back
- #define ll long long
- #define mp make_pair
- #define ff first
- #define ss second
- #define pii pair<int,int>
- #define sq(x) ((x)*(x))
- #define all(v) v.begin(),v.end()
- const int MOD = 1000*1000*1000 + 7;
- const double PI = 3.14159265;
- bool check(int sum1, int n) // checks if it is possible to make any number with sum s1 and n digits
- {
- // sum1 is sum of digits // check basically checks if u can have a n digits number with sum = s1
- if((sum1>(9*n)||(sum1<0))) // understood ?
- return false;
- else
- return true;
- }
- int main()
- {
- fastio();
- int m,s;
- cin>>m>>s;
- int sum=s,nod=m,num,flag; // nod = m
- if (m==1&&s==0)
- cout<<"0 0";
- else if((s==0)||(s>(9*m))) // not possible
- {
- cout<<"-1 -1";
- return 0;
- }
- else // minimum number
- {
- for (int i = 0; i < nod; ++i)
- {
- if(i==0)
- {
- num=1,flag=1; // num = 1; (first digit can't be 0)
- while(flag)
- {
- if(check((sum-num),(nod-i-1)))
- {
- cout<<num; // smallest possible digit
- flag--;
- sum-=num; // subtracting from num
- }
- else
- num++;
- }
- }
- else
- {
- num=0,flag=1; // num = 0;
- while(flag)
- {
- if(check((sum-num),(nod-i-1)))
- {
- cout<<num;
- flag--;
- sum-=num;
- }
- else
- num++;
- }
- }
- }
- cout<<" ";
- sum=s;
- nod=m;
- while((sum>9)&&(nod>0)) // printing 9s
- {
- cout<<9;
- nod--;
- sum-=9;
- }
- if(nod!=0)
- {
- cout<<sum;
- nod--;
- }
- while(nod!=0)
- {
- cout<<0;
- nod--;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement