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;
}
相关推荐
阿里嘎多学长18 分钟前
2026-10-12 GitHub 热点项目精选
开发语言·程序员·github·代码托管
wangchunyu1141 小时前
Python 数据可视化实战入门教程
开发语言·python·信息可视化
Nil2081 小时前
leetcode 198打家劫舍
算法·leetcode·职场和发展
Shaoshing2 小时前
前缀和与差分
java·数据结构·算法·前缀和·差分
mmmmath_32 小时前
LeetCode.429.N叉树的层序遍历
数据结构·leetcode
wuyk5552 小时前
嵌入式驱动开发:量产级工程化实战(第9篇)——低功耗下的通信可靠性
c语言·驱动开发·stm32·单片机·嵌入式硬件
loulanyue_2 小时前
构建房产认知决策智能:Harness底座与AI自进化的技术实践——读贝壳首席算法科学家尹俊希2026云栖专场演讲
人工智能·算法
学逆向的3 小时前
C 突破编译器限制
c语言·开发语言·网络安全
碧海银沙音频科技研究院3 小时前
基于炬芯ATS录音卡BLE控制协议
人工智能·嵌入式硬件·算法·语音识别
jimy13 小时前
C++ 虚函数表:基类和派生类共用一张 vtable 吗?
开发语言·c++