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
  1. 2 15
Output
  1. 69 96
Input
  1. 3 0
Output
  1. -1 -1
      
      题意是:给出ms。求出长度为m的数,各个位上的数加起来为s。求最小的和最大的数。
      贪心的思想,对于最小的,从最右边开始,拿最大的往上怼,不能有前导零(而求最大时可以后面有零,这是区别)
            对于最大的,从最左边开始,拿最大的往上怼,不用在乎后面为0,因为这样才能为最大。
      对与输出为-1 -1 的情况,如果m*9<s,或者:s=0 时,只有m=1时有答案0,0m>1时为-1 -1
      
  1. #include<iostream>
  2. #include<cstdio>
  3. using namespace std;
  4. typedef long long ll;
  5. ll a[],b[];
  6. ll tot=;
  7. int main()
  8. {
  9. ll m,s;
  10. while(cin>>m>>s)
  11. {
  12. if(m*<s||(s<&&m!=))
  13. cout<<"-1 -1"<<endl;
  14. else
  15. {
  16. int m1=m,s1=s;
  17. for(int i=m-;i>=;i--)
  18. {
  19. if(s>)
  20. {
  21. a[i]=;
  22. s-=;
  23. }  //还没到最后一位,尽量大得放
  24. else if(i!=)
  25. {
  26. a[i]=s-;
  27. s=;  //这个是为了前一位尽量为1,因为此时已经小于9了;如果还没到第一位,而s=1,那么就上0;
  28. }
  29. else
  30. {
  31. a[i]=s;//到第一位了,那就没得分了,直接往上放。
  32. }
  33. }      //如果大于9,肯定往上放9。
  34. for(int i=;i<m1;i++)
  35. {
  36. if(s1>)
  37. {
  38. b[i]=;
  39. s1-=;
  40. }
  41. else
  42. {
  43. b[i]=s1;
  44. s1=;
  45. }
  46.  
  47. }
  48. for(int i=;i<m;i++)
  49. printf("%d",a[i]);
  50. printf(" ");
  51. for(int i=;i<m;i++)
  52. printf("%d",b[i]);
  53. cout<<endl;
  54. }
  55. }
  56. }

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. 12 MySQL存储过程与函数

    存储过程和函数     存储过程和函数是事先经过编译并存储在数据库中的一段SQL语句的集合.     调用存储过程和函数可以简化应用开发人员的工作,减少数据在数据库和应用服务器之间的传输,提高数据处理 ...

  2. msf自动连接postgresql配置

    今天做了一下msf连接数据库的配置,中间碰到了一些坑点这里就不详细叙述了,开始正确的操作方式. 首先对postgresql进行配置以方便连接. root@kali:~# service postgre ...

  3. Idea 打开多profile注意事项

    Maven项目经常会有多个profile,可以方便在编译时指定profile. 如果有多个profile,idea 在打开工程后默认配置可能会有些问题. 例如: 最近在编译一个项目:https://g ...

  4. Vue - slot-scope="scope" 的意义

      <template slot-scope="scope">                     <el-button type="primary ...

  5. laravel.01.一些细节

    0:参考1,参考2,参考3,参考4,参考5 1.读取项目的配置文件内容,比如app.php下的name属性,用config('app.name','default-value'); 2.读取.ENV文 ...

  6. JAVA-数据类型-复习

    JAVA-数据类型-复习 Java中,一共有8种数据类型,4种整型,2种浮点型,1种用于表示Unicode编码的字符单元的字符类型char,1种布尔类型. 整型 类型 存储需求(字节)一个字节包含8个 ...

  7. hdu 1671 Phone List 统计前缀次数

    Phone List Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  8. TX2_安装view_team

    TX2上的帐号是:1317149963,dc200820305233 参考网站:https://blog.csdn.net/qq_33512213/article/details/90050792 安 ...

  9. export环境变量

    /etc/profile和/etc/profile.d/区别 [root@zzx conf]# vim /etc/profile.d/tomcat.sh   添加如下内容再运行脚本就可以添加环境变量 ...

  10. JMP CALL RET

    一.JMP指令(修改EIP的值)(第一个修改EIP的指令) 三种方法 :JMP 立即数 JMP  寄存器 JMP  内存 EIP 之前介绍过,EIP存放的值就是cpu下一次要执行的地址 1.之前学过要 ...