You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that has length m and sum of digits s. The required numbers should is non-negative integers written in the decimal base without leading zeroes.
Input
The single line of the input contains a pair of integers m, s (1≤ m ≤ 100, 0 ≤ s ≤900)-the length and the sum of the digits of the required numbers.
Output
In the output print the pair of the required non-negative integer Numbers-first the minimum possible number, then-the Maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1-1" (without the quotes).
Sample Test (s) input
2 15
Output
69 96
Input
3 0
Output
-1-1
/* Greedy for min first to ensure that there are 1 from the back to add, if the addition after the S, indicating no, if not even 1 is not so much for Max, if s 9 is not enough for the other special cases to be sentenced, such as 1 0 pit point should be output 0 0. The other 0 are -1-1*/#include <cstdio> #include <cstring> #include <algorithm>using namespace Std;int main ( ) {int n,s; int a[110]; while (~SCANF ("%d%d", &n, &s)) {if (n = = 1 && s = = 0) {printf ("0 0\n"); Continue } if (n = = 0 | | s = = 0) {if (n== 1 && s = = 0); else {printf (" -1-1\n"); Continue }} memset (A, 0, sizeof (a)); int temp = s; S--; A[1] = 1; int pos = n; int flag = 0; while (S > 0) {if (S <= 8) {a[pos--] + = s; s = 0; } else{a[pos--] = 9; S-= 9; } if (pos = = 0) break; } int flag1 = 0; int sum1 = 0; for (int i = 1; I <= n; i++) {sUM1 + = A[i]; if (A[i] > 9) Flag1 = 1; } if (sum1! = Temp | | flag1 = = 1) printf ("-1"); else {for (int i = 1; I <= n; i++) printf ("%d", a[i]); printf (""); } memset (A, 0, sizeof (a)); s = temp; for (int i = 1; I <= n; i++) {if (S <= 8) {A[i] = S;s = 0;} else {A[i] = 9; s-= 9;} } int sum = 0; for (int i = 1; I <= n; i++) sum + = A[i]; if (sum! = Temp | | a[1] = = 0) printf (" -1\n"); else {for (int i = 1; I <= n; i++) printf ("%d", a[i]); Puts (""); }} return 0;}
Codeforces Round #277.5 (Div. 2)--c greedy--given Length and Sum of Digits