Codeforces Round #277.5 (Div. 2)(C题)
1 second
256 megabytes
standard input
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.
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.
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).
2 15
69 96
3 0
-1 -1
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std; bool can(int m, int s)
{
if(s >= 0 && 9*m >= s) return true;
else return false;
}
int main()
{
int m,s;
cin>>m>>s;
if(!can(m,s))
{
cout<<"-1"<<" "<<"-1"<<endl;
return 0;
}
if(m == 1)
{
if(s >= 10)
{
cout<<"-1"<<" "<<"-1"<<endl;
}
else cout<<s<<" "<<s<<endl;
}
else {
if(s == 0) cout<<"-1"<<" "<<"-1"<<endl;
else { string minn, maxn;
int sum = s; for(int i = 1; i <= m; i++)
for(int j = 0; j < 10; j++)
{
if((j > 0 || (j == 0 && i > 1) ) && can(m - i, sum - j))
{
minn += char('0' + j);
sum -= j;
break;
}
} sum = s;
for(int i = 1; i <= m; i++)
for(int j = 9; j >= 0; j--)
{
if(can(m - i, sum - j))
{
maxn += char('0' + j);
sum -= j;
break;
}
} cout<<minn<<" "<<maxn<<endl; }
}
return 0;
}
Codeforces Round #277.5 (Div. 2)(C题)的更多相关文章
- Codeforces Round #277.5 (Div. 2) ABCDF
http://codeforces.com/contest/489 Problems # Name A SwapSort standard input/output 1 s, 256 ...
- Codeforces Round #277.5 (Div. 2)
题目链接:http://codeforces.com/contest/489 A:SwapSort In this problem your goal is to sort an array cons ...
- Codeforces Round #277.5 (Div. 2) --E. Hiking (01分数规划)
http://codeforces.com/contest/489/problem/E E. Hiking time limit per test 1 second memory limit per ...
- Codeforces Round #277.5 (Div. 2)B——BerSU Ball
B. BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #277.5 (Div. 2)-D. Unbearable Controversy of Being
http://codeforces.com/problemset/problem/489/D D. Unbearable Controversy of Being time limit per tes ...
- 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 ...
- Codeforces Round #277.5 (Div. 2)-B. BerSU Ball
http://codeforces.com/problemset/problem/489/B B. BerSU Ball time limit per test 1 second memory lim ...
- Codeforces Round #277.5 (Div. 2)-A. SwapSort
http://codeforces.com/problemset/problem/489/A A. SwapSort time limit per test 1 second memory limit ...
- Codeforces Round #277.5 (Div. 2) A,B,C,D,E,F题解
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud A. SwapSort time limit per test 1 seco ...
随机推荐
- 在Myeclipse8.5中安装findbugs方法
step 1:首先从官网下载findbugs插件:http://downloads.sourceforge.net/project/findbugs/findbugs%20eclipse%20plug ...
- eslint规范项目代码
安装一系列eslint插件后,填写eslint配置,配置如下 .editorconfig root = true [*] charset = utf-8 indent_style = space in ...
- (转)对称加密与非对称加密,以及RSA的原理
一 概述 二对称加密和非对称加密 对称加密 非对称加密 区别 三RSA原理 整数运算 同余运算 当模数为合数n时 当模数为质数p的时候 离散对数问题 RSA原理 一 , 概述 在现代密码学诞生以前,就 ...
- A.Equals(B)和A==B的区别
Equals 和 == 都是用于比较. 如果a和b都是值类型,则a.Equals(b) 和 a == b 结果相同,但是在引用类型是它们的行为是不同的: string a = new string(n ...
- AGC 26 F Manju Game
$\DeclareMathOperator{\sw}{sw}$ $\DeclareMathOperator{\sb}{sb}$ $\DeclareMathOperator{\dp}{dp}$ 用 $\ ...
- [NOI2003][bzoj1507] 文本编辑器 editor [splay]
其实看明白了就是一道水题 毕竟模板 splay敲一发,插入一个串的时候先把它构建成一棵平衡树,再挂到原来的splay上面去即可 没别的了,上代码 #include<iostream> #i ...
- BZOJ3295 [Cqoi2011]动态逆序对 【CDQ分治】
题目 对于序列A,它的逆序对数定义为满足i 输入格式 输入第一行包含两个整数n和m,即初始元素的个数和删除的元素个数.以下n行每行包含一个1到n之间的正整数,即初始排列.以下m行每行一个正整数,依次为 ...
- 【01】react 之 hello world
React 起源于 Facebook 的内部项目,因为该公司对市场上所有 JavaScript MVC 框架,都不满意,就决定自己写一套,用来架设 Instagram 的网站.做出来以后,发现这套东西 ...
- python c++ Visual Studio相关 Unable to find vcvarsall.bat问题
使用Cython编译包的时候报错: Unable to find vcvarsall.bat 说明:https://jingyan.baidu.com/article/adc815138162e8f7 ...
- Android 中利用ViewFlipper 滑动屏幕切换页面,ListView展示数据
首先新建一个Android项目,命名为ViewFlipperTest 如图:项目机构,本项目主要操作图中红色箭头标注的文件 1.HgroupAdapter.java文件代码↓主要实现listview数 ...