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;
}
相关推荐
虚心的百褶裙4 分钟前
JavaScript性能优化
开发语言·javascript·性能优化
凯瑟琳.奥古斯特11 分钟前
二分查找解力扣1011最优运载能力
开发语言·c++·算法·leetcode·职场和发展
学计算机的计算基19 分钟前
二叉树算法下篇:递归核心技巧与高频面试题详解
java·笔记·算法
Tim_1028 分钟前
【C++】014、左值与右值的区别
开发语言·c++
水龙吟啸31 分钟前
华为2026.6.24机考选择题+编程题【速刷敲黑板】
人工智能·深度学习·算法·机器学习·华为
天空'之城35 分钟前
Linux 系统编程 14:Reactor 反应堆模式
linux·开发语言·网络编程·reactor 反应堆模式
Eloudy40 分钟前
全文 - Evolution Strategies as a Scalable Alternative to Reinforcement Learning
人工智能·算法
Zhou1411361 小时前
Java常见面试题7
java·开发语言
^yi1 小时前
【C++】类和对象(全)
开发语言·c++
Yang_jie_031 小时前
笔记:数据结构(链表)
数据结构·笔记·链表