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).

Examples

Input
2 15
Output
69 96
Input
3 0
Output
-1 -1
  
  题意是:给出m,s。求出长度为m的数,各个位上的数加起来为s。求最小的和最大的数。
  贪心的思想,对于最小的,从最右边开始,拿最大的往上怼,不能有前导零(而求最大时可以后面有零,这是区别)
        对于最大的,从最左边开始,拿最大的往上怼,不用在乎后面为0,因为这样才能为最大。
  对与输出为-1 -1 的情况,如果m*9<s,或者:s=0 时,只有m=1时有答案0,0。m>1时为-1 -1;
  
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
ll a[],b[];
ll tot=;
int main()
{
ll m,s;
while(cin>>m>>s)
{
if(m*<s||(s<&&m!=))
cout<<"-1 -1"<<endl;
else
{
int m1=m,s1=s;
for(int i=m-;i>=;i--)
{
if(s>)
{
a[i]=;
s-=;
}  //还没到最后一位,尽量大得放
else if(i!=)
{
a[i]=s-;
s=;  //这个是为了前一位尽量为1,因为此时已经小于9了;如果还没到第一位,而s=1,那么就上0;
}
else
{
a[i]=s;//到第一位了,那就没得分了,直接往上放。
}
}      //如果大于9,肯定往上放9。
for(int i=;i<m1;i++)
{
if(s1>)
{
b[i]=;
s1-=;
}
else
{
b[i]=s1;
s1=;
} }
for(int i=;i<m;i++)
printf("%d",a[i]);
printf(" ");
for(int i=;i<m;i++)
printf("%d",b[i]);
cout<<endl;
}
}
}

B - Given Length and Sum of Digits... CodeForces - 489C (贪心)的更多相关文章

  1. Codeforces Round #277.5 (Div. 2)-C. Given Length and Sum of Digits...

    http://codeforces.com/problemset/problem/489/C C. Given Length and Sum of Digits... time limit per t ...

  2. CodeForces 489C Given Length and Sum of Digits... (贪心)

    Given Length and Sum of Digits... 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/F Descr ...

  3. Codeforces Round #277.5 (Div. 2)C——Given Length and Sum of Digits...

    C. Given Length and Sum of Digits... time limit per test 1 second memory limit per test 256 megabyte ...

  4. codeforces#277.5 C. Given Length and Sum of Digits

    C. Given Length and Sum of Digits... time limit per test 1 second memory limit per test 256 megabyte ...

  5. CodeForces 489C Given Length and Sum of Digits... (dfs)

    C. Given Length and Sum of Digits... time limit per test 1 second memory limit per test 256 megabyte ...

  6. codeforces 489C.Given Length and Sum of Digits... 解题报告

    题目链接:http://codeforces.com/problemset/problem/489/C 题目意思:给出 m 和 s,需要构造最大和最小的数.满足长度都为 m,每一位的数字之和等于 s. ...

  7. CodeForces 489C (贪心) Given Length and Sum of Digits...

    题意: 找出m位且各个数位数字之和为s的最大和最小整数,不包括前导0(比如说003是非法的),但0是可以的. 分析: 这题是用贪心来做的,同样是m位数,前面的数字越大这个数就越大. 所以写一个can( ...

  8. Codeforces 489C Given Length and Sum of Digits...

    m位长度,S为各位的和 利用贪心的思想逐位判断过去即可 详细的注释已经在代码里啦~ //#pragma comment(linker, "/STACK:16777216") //f ...

  9. CF 277.5 C.Given Length and Sum of Digits.. 构造

    #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #incl ...

随机推荐

  1. Django(十)模型:django模型类对数据库的:增/删/改/查、自关联、管理器、元选项(指定表名)

    一.插入.更新和删除 调用一个模型类对象的save方法的时候就可以实现对模型类对应数据表的插入和更新. 调用一个模型类对象的delete方法的时候就可以实现对模型类对应数据表数据的删除. 二.自关联 ...

  2. Ubuntu下搭建yocto

    参考自: https://www.jianshu.com/p/f6e0debb5e1f https://blog.csdn.net/qq_31041847/article/details/902114 ...

  3. 基础知识 SafeSEH DEP ASLR SEHOP

    大多是0day书上抄的 1.SafeSEH 机制: 首先:内存中有SEH表的备份(加密过的) 在调用异常出来函数前,RtlDispatchException()函数中的行为: Ⅰ.检查异常处理链是否位 ...

  4. python面试题整理(一)

    python基础:1.列表生成式和生成器表达式有什么区别 我说的是首先写法不一样,列表生成式用[],生成器表达式用(),其次列表生成是一次性生成一个完整的列表,生成器表达式返回的是一个一个的值,占用内 ...

  5. css 基础知识 (待完善...)

    CSS   1.position 属性     对元素进行定位.       absolute         相对于 非static类型的position 的 第一个(临近的) 父元素 进行定位. ...

  6. hibernate注解 笔记

    1.hibernate使用@where实现条件过滤功能 其里面只有一个参数clause,完整用法是: @Where(clause = "VALID_FLAG=1") 可以加在实体类 ...

  7. 从零开始Windows环境下安装python+tensorflow

    从零开始Windows环境下安装python+tensorflow 2017年07月12日 02:30:47 qq_16257817 阅读数:29173 标签: windowspython机器学习te ...

  8. 对OpenSSL心脏出血漏洞的试验

    1.安装OpenSSL环境 sudo apt-get install openssl sudo pip install pyopenssl(中间会提示ffi.h 没有那个文件或目录,sudo apt- ...

  9. Community Cloud零基础学习(三)Partner Account

    本篇参考:http://salesforce.vidyard.com/watch/bLE3QNRSej2iasw9vvc6Tk http://salesforce.vidyard.com/watch/ ...

  10. python运算表达式

    运算符1.算术运算符:+,-,*,/,//(求整商),%,**(求多次方,左边为数,右边为多少次方)2.关系运算符:>,<,==,<=,>=,!=3.测试运算:in,not i ...