Codeforces Round #277.5 (Div. 2) C

来源:互联网 发布:java鱼雷多重 编辑:程序博客网 时间:2024/05/16 01:56

题目: http://codeforces.com/contest/489/problem/C

C. Given Length and Sum of Digits...
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.

Input

The single line of the input contains a pair of integers ms (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
#include<stdio.h>#include<iostream>#include<math.h>#include<stdlib.h>#include<ctype.h>#include<algorithm>#include<vector>#include<string.h>#include<queue>#include<stack>#include<set>#include<map>#include<sstream>#include<time.h>#include<malloc.h>using namespace std;int n,m;int a[110];int main (){    while (scanf("%d %d",&n,&m)!=EOF)    {        if ( m == 0 )        {            if ( n == 1)                printf("0 0\n");            else                printf("-1 -1\n");        }        else if ( n*9 < m)            printf("-1 -1\n");        else        {            {                memset(a,0,sizeof(a));                a[n-1] = 1;                int ans = m-1;                for(int i=0 ;ans && i<n;i++)                {                    while (ans != 0 && a[i]<9)                    {                        ans--;                        a[i]++;                    }                }                for(int i=n-1;i>=0;i--)                    printf("%d",a[i]);                printf(" ");            }            {                memset(a,0,sizeof(a));                a[0]= 1 ;                int ans = m-1;                for(int i=0;ans && i<n;i++)                {                    while (ans !=0 && a[i]<9)                    {                        ans --;                        a[i]++;                    }                }                for(int i=0 ;i<n;i++)                    printf("%d",a[i]);                printf("\n");            }        }    }    return 0;}


0 0
原创粉丝点击