1400*C. Given Length and Sum of Digits...(贪心)

Problem - 489C - Codeforces

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
int m,s,a[110];
signed main(){
	scanf("%d%d",&m,&s);
	if(s>m*9) puts("-1 -1");
	else if(s==0&&m>1) puts("-1 -1");
	else if(s==0&&m==1) puts("0 0");
	else{
		int t=s;
		t-=1;
		a[1]=1;
		for(int i=m;i>=1;i--){
			if(t>=9){
				a[i]+=9;
				t-=9;
			}
			else{
				a[i]+=t;
				break;
			}
		}
		for(int i=1;i<=m;i++) cout<<a[i];
		cout<<" ";
		t=s;
		memset(a,0,sizeof a);
		for(int i=1;i<=m;i++){
			if(t>=9){
				a[i]+=9;
				t-=9;
			}
			else{
				a[i]+=t;
				break;
			}
		}
		for(int i=1;i<=m;i++) cout<<a[i];
	}
	return 0;
}
相关推荐
anew___1 分钟前
2026年Python爬虫技术完全指南:从入门到实战
开发语言·爬虫·python
Penfy_Z3 分钟前
【Python LLM 调用踩坑】Connection error 终极解决方案!npm 代理导致阿里云通义千问接口连接失败
开发语言·python·npm
星辰徐哥4 分钟前
Python AI基础:Python面向对象编程
开发语言·人工智能·python
Coder-magician4 分钟前
《代码随想录》刷题打卡day15:二叉树part05
数据结构·c++·算法
小宁爱Python4 分钟前
Python 依赖管理神器:requirements.txt 从安装到实战全指南
开发语言·python
Kurisu_红莉栖5 分钟前
力扣56合并区间
算法·leetcode
Darling噜啦啦5 分钟前
二叉树与递归算法实战:从树结构到 LeetCode 爬楼梯,一文吃透前端数据结构与递归思维
前端·javascript·数据结构
Irissgwe11 分钟前
算法的时间复杂度和空间复杂度
数据结构·c++·算法·c·时间复杂度·空间复杂度
随意起个昵称12 分钟前
区间dp-基础题目3(永别)
c++·算法
俊俊谢17 分钟前
[python]FastAPI + 自建SSE 踩坑全记录
开发语言·python·fastapi