https://codeforces.com/problemset/problem/489/C

C. Given Length and Sum of Digits...

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

Examples

input

2 15

output

69 96

input

3 0

output

-1 -1

题意:

给定一个数m 和 一个长度s,计算最大和最小在s长度下的十进制各位数和为m的值

注意如果无法生成,即输出两个-1

题解:

有个小坑,在输出最大值时得注意下k 是否为 0

#include<bits/stdc++.h>
using namespace std;
int main()
{
int m, s, i, k;
cin >> m >> s;
if (s < 1 && m>1 || s > m * 9)
cout << -1 << " " << -1 << endl;
else {
for (i = m - 1, k = s; i >= 0; i--) {
int j = max(0, k - 9 * i);
if (j == 0 && i == m - 1 && k) j = 1;
cout << j;
k -= j;
}
cout << ' ';
for (i = m - 1, k = s; i >= 0; i--) {
int j = min(9, k);
cout << j;
k -= j;
}
}
}

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

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

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

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

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

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

  6. B - Given Length and Sum of Digits... CodeForces - 489C (贪心)

    You have a positive integer m and a non-negative integer s. Your task is to find the smallest and th ...

  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. Codeforces Round #667 (Div. 3) D. Decrease the Sum of Digits (贪心)

    题意:给你一个正整数\(n\),每次可以对\(n\)加一,问最少操作多少次是的\(n\)的所有位数之和不大于\(s\). 题解:\(n\)的某个位置上的数进位,意味这后面的位置都可以被更新为\(0\) ...

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

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

随机推荐

  1. LabVIEW用布尔控件实现上升沿和下降沿触发

    我们利用了第三方布尔控件来记录摇杆的高低电平状态,并和摇杆布尔控件组成布尔数组,转换成十进制数进行判断上升沿和下降. 上升沿触发.例如一开始第三方布尔控件为T,夹紧松开布尔控件为F,然后我这时把摇杆控 ...

  2. 使用Tensorrt部署,C++ API yolov7_pose模型

    使用Tensorrt部署,C++ API yolov7_pose模型 虽然标题叫部署yolov7_pose模型,但是接下来的教程可以使用Tensorrt部署任何pytorch模型. 仓库地址:http ...

  3. 快速认识,前端必学编程语言:JavaScript

    JavaScript是构建Web应用必学的一门编程语言,也是最受开发者欢迎的热门语言之一.所以,如果您还不知道JavaScript的用处.特点的话,赶紧补充一下这块基础知识. JavaScript 是 ...

  4. ACPM高效C++组件管理让音视频终端SDK性能更好、稳定性更高

    本专栏将分享阿里云视频云MediaBox系列技术文章,深度剖析音视频开发利器的技术架构.技术性能.开发能效和最佳实践,一起开启音视频的开发之旅.本文为MediaBox技术架构篇,重点从 ACPM介绍. ...

  5. JavaScript数组及方法总结

    数组的创建方法 1.常规方式: var myCars=new Array(); myCars[0]="Saab"; myCars[1]="Volvo"; myC ...

  6. Linux云服务器购买,学习

    购买云服务器的初衷 作为一名自动化测试工程师,不能仅限于掌握工作上的业务和代码,业余时间需要找点开源项目来练习性能.接口.UI自动化. 云服务器购买 https://www.aliyun.com/ 我 ...

  7. 关于开放签CA数字证书设计的思考

    这几天在调研CA数字证书以及思考如何在产品中集成使用CA数字证书,主要的目的和方向有以下几点: 有法律效力的电子文件的签署需要使用权威的证书颁发机构(CA)颁发的数字证书: 我们希望找到更便宜的证书方 ...

  8. ncurses 与 menu

    ncurses 与 menu 一下位ncurses和菜单库menu的demo程序 #include <menu.h> #include <ncurses.h> #include ...

  9. Java 中时间对象的序列化

    在 Java 应用程序中,时间对象是使用地比较频繁的对象,比如,记录某一条数据的修改时间,用户的登录时间等应用场景.在传统的 Java 编程中,大部分的程序员都会选择使用 java.uti.Date ...

  10. 拓扑排序软件设计——ToplogicalSort_app(含有源码、需求分析、可行性分析、概要设计、用户使用手册)

    @ 目录 前言 1. 需求分析 2. 可行性分析 2.1 简介 2.2 技术可行性分析 2.2.1 技术实现方案 2.2.2 开发人员技能要求 2.2.3 可行性 2.3 操作可行性分析 2.4 结论 ...