Description

You are given a positive integer nn.

Let S(x) be sum of digits in base 10 representation of xx, for example, S(123)=1+2+3=6, S(0)=0.

Your task is to find two integers a,ba,b, such that 0≤a,b≤n, a+b=n and S(a)+S(b) is the largest possible among all such pairs.

Input

The only line of input contains an integer nn (1≤n≤1012).

Output

Print largest S(a)+S(b) among all pairs of integers a,ba,b, such that 0≤a,b≤n and a+b=n.

Sample Input

Input
35
Output
17
Input
10000000000
Output
91

Hint

In the first example, you can choose, for example, a=17 and b=18, so that S(17)+S(18)=1+7+1+8=17. It can be shown that it is impossible to get a larger answer.

In the second test example, you can choose, for example, a=5000000001 and b=4999999999, with S(5000000001)+S(4999999999)=91. It can be shown that it is impossible to get a larger answer.

相信不少人wa是这个代码

 #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define swap(a,b) (a=a+b,b=a-b,a=a-b)
#define maxn 320007
#define N 100000000
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e 2.718281828459045
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define read(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define memset(x,y) memset(x,y,sizeof(x))
#define Debug(x) cout<<x<<" "<<endl
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define ll long long
//std::ios::sync_with_stdio(false);
//cin.tie(NULL);
using namespace std; int main()
{
ll n,a,b;
cin>>n;
ll m=n,k=;
while(m>=k)
{
k=k*+;
}
k/=;
//cout<<k<<endl;
a=k;
b=n-k;
ll sum=;
while(a)
{
sum+=a%;
a/=;
}
while(b)
{
sum+=b%;
b/=;
}
cout<<sum<<endl;
return ;
}

你们可以尝试一下123这个样例,输出为15,但正确答案为24(99+24)。

AC代码如下:

 #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define swap(a,b) (a=a+b,b=a-b,a=a-b)
#define maxn 320007
#define N 100000000
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e 2.718281828459045
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define read(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define memset(x,y) memset(x,y,sizeof(x))
#define Debug(x) cout<<x<<" "<<endl
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define ll long long
//std::ios::sync_with_stdio(false);
//cin.tie(NULL);
using namespace std; int main()
{
ll n,a,b;
cin>>n;
ll m=n,k=;
while(m>=k)
{
k=k*+;
}
k/=;
//cout<<k<<endl;
a=k;
b=n-k;
ll sum=;
while(a)
{
sum+=a%;
a/=;
}
while(b)
{
sum+=b%;
b/=;
}
cout<<sum<<endl;
return ;
}

Maximum Sum of Digits(CodeForces 1060B)的更多相关文章

  1. CodeForces 1060 B Maximum Sum of Digits

    Maximum Sum of Digits You are given a positive integer n. Let S(x)S(x) be sum of digits in base 10 r ...

  2. (CodeForces - 5C)Longest Regular Bracket Sequence(dp+栈)(最长连续括号模板)

    (CodeForces - 5C)Longest Regular Bracket Sequence time limit per test:2 seconds memory limit per tes ...

  3. cf#513 B. Maximum Sum of Digits

    B. Maximum Sum of Digits time limit per test 2 seconds memory limit per test 512 megabytes input sta ...

  4. Sorted Adjacent Differences(CodeForces - 1339B)【思维+贪心】

    B - Sorted Adjacent Differences(CodeForces - 1339B) 题目链接 算法 思维+贪心 时间复杂度O(nlogn) 1.这道题的题意主要就是让你对一个数组进 ...

  5. 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 ...

  6. 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 ...

  7. [题解]Yet Another Subarray Problem-DP 、思维(codeforces 1197D)

    题目链接:https://codeforces.com/problemset/problem/1197/D 题意: 给你一个序列,求一个子序列 a[l]~a[r] 使得该子序列的 sum(l,r)-k ...

  8. (CodeForces 558C) CodeForces 558C

    题目链接:http://codeforces.com/problemset/problem/558/C 题意:给出n个数,让你通过下面两种操作,把它们转换为同一个数.求最少的操作数. 1.ai = a ...

  9. HDU 3415 Max Sum of Max-K-sub-sequence(单调队列)

    转载请注明出处:http://blog.csdn.net/u012860063 Max Sum of Max-K-sub-sequence Time Limit: 2000/1000 MS (Java ...

随机推荐

  1. Type Conversion

    文章著作权归作者所有.转载请联系作者,并在文中注明出处,给出原文链接. 本文原更新于作者的github博客,这里给出链接. 什么是转换 转换是接受一个类型的值并使用它作为另一个类型的等价值的过程.转换 ...

  2. 【题解】Luogu P2347 砝码称重

    正经·DP题解 一道非常好的背包练手题( sto(注:原思路来源 SLYZ_0120 的题解)orz 开始这道题 1.输入六个数,存进数组中 2.初始化 f 数组为0. f [ i ] 表示重量为 i ...

  3. Exp4 恶意代码分析 20164303 景圣

    Exp4 恶意代码分析 实验内容 实验点一:系统运行监控 (1)使用如计划任务,每隔一分钟记录自己的电脑有哪些程序在联网,连接的外部IP是哪里.运行一段时间并分析该文件,综述一下分析结果.目标就是找出 ...

  4. [ERROR] --gtid-mode=ON or UPGRADE_STEP_1 or UPGRADE_STEP_2 requires --log-bin and --log-slave-updates

    centos7.5 做基于GTID的主从重启从库报错 问题: [root@db01-51 ~]# tail -50 /application/mysql/data/db01-51.err 2019-0 ...

  5. Cordova开箱注意事项

    在进行cd 目录切换的时候 一定要 注意大小写 不然 node_modules 下的依赖包 会报错 区分大小写 Cordova 在打包的时候报错 一般是版本或sdk问题 cordova 的版本要和co ...

  6. 获取占用fd最大的前20个进程

    for x in `ps -eF| awk '{ print $2 }'`;do echo `ls /proc/$x/fd 2> /dev/null | wc -l` $x `cat /proc ...

  7. VirtualBox中安装CentOS 7_Linux

    准备条件 在自己真实机上已经安装了VirtualBox虚拟机,具体安装方法可以参考Linux公社的文章. 下载CentOS-7的镜像 1. 在虚拟机中创建虚拟电脑 如图点击新建按钮,开始新建虚拟机电脑 ...

  8. VS的工作目录和输出目录

    C+ +项目,解决方案总文件夹下就只包含解决方案配置文件sln和一个项目总文件夹和一个Debug文件夹以及一个Release文件夹(共四个东东,其中Debug和Release文件夹中存放最终生成的结果 ...

  9. B/S架构

    B/S架构即浏览器和服务器架构模式.它是随着Internet技术的兴起,对C/S架构的一种变化或者改进的架构.在这种架构下,用户工作界面是通过WWW浏览器来实现,极少部分事务逻辑在前端(Browser ...

  10. 在webstorm中配置sass的自动编译,并且可以指定编译后的css的目录.

    参考: WebStorm-2018.2-Help-Sass, Less, and SCSS 作者:tobyDing链接:https://www.jianshu.com/p/0fe52f149cab來源 ...