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. [WPF]动手写一个简单的消息对话框

    消息对话框是UI界面中不可或缺的组成部分,用于给用户一些提示,警告或者询问的窗口.在WPF中,消息对话框是系统原生(user32.dll)的MessageBox,无法通过Style或者Template ...

  2. Spyder5老是闪退报错 "Blowfish has been deprecated "的解决方法

    目录 一.前言 我的运行环境 二.解读报错 三.解决方法 四.打开spyder5 一.前言 本人在学习python时图省事选择直接安装Anaconda3,用spyder5来进行学习,可是比较蛋疼的是安 ...

  3. Kepware楼宇自控BACnet/IP驱动

    BACnet/IP驱动是楼宇自动化设备驱动的集合,为用户提供一种方便快捷的楼宇自动化设备数采解决方案.只需要通过简单的配置就可以将常见的BACnet/IP协议设备无缝连接到 HMI/SCADA.MES ...

  4. 赛意SMOM和金蝶云星空单据接口对接

    赛意SMOM和金蝶云星空单据接口对接 数据源系统:金蝶云星空 金蝶K/3Cloud在总结百万家客户管理最佳实践的基础上,提供了标准的管理模式:通过标准的业务架构:多会计准则.多币别.多地点.多组织.多 ...

  5. 多维度分析数据的软件,BI软件不就是吗

    BI软件(Business Intelligence Software)是一种用于多维度分析数据的工具,可以帮助企业从海量数据中提取有价值的洞察力,并为决策者和业务用户提供可视化.交互式的报表和仪表盘 ...

  6. C# 字节数组、各进制字符串数据互转

    前言 日常开发过程中,格式转换是必不可少的重要环节,经常是十进制转十六进制.十六进制转byte数组又转换回来来回转换,最然进制转换很基础同时 C# 也提供了很多直接方便进行格式转换的方法,但是封装一个 ...

  7. 使用vLLM和ChatGLM3-6b批量推理

    当数据量大的时候,比如百万级别,使用 ChatGLM3-6b 推理的速度是很慢的.发现使用 vLLM 和 ChatGLM3-6b 批量推理极大的提高了推理效率.本文主要通过一个简单的例子进行实践. 1 ...

  8. 数字孪生技术与VR技术的结合会为我们带来什么?

    数字孪生技术与虚拟现实(VR)技术的结合为我们打开了全新的可能性和机遇.这个强大的联合为各个领域带来了巨大的影响和创新. 首先,数字孪生技术与VR技术的结合可以为设计和规划过程提供更直观.身临其境的体 ...

  9. android webview(外部浏览器)调起app

    最近写的项目中涉及外部浏览器以及项目webview中调起app,所以总结下,和大家分享下. 总的实现方法还是比较简单的, 1:在清单中注册 首先在AndroidManifest文件中,注册一个过滤器 ...

  10. C++ Qt开发:SqlRelationalTable关联表组件

    Qt 是一个跨平台C++图形界面开发库,利用Qt可以快速开发跨平台窗体应用程序,在Qt中我们可以通过拖拽的方式将不同组件放到指定的位置,实现图形化开发极大的方便了开发效率,本章将重点介绍SqlRela ...