Problem 1565 - B - Magic

Problem 1565 - B - Magic
Time Limit: 1000MS   Memory Limit: 65536KB   
Total Submit: 477  Accepted: 180  Special Judge: No
Description
Here are n numbers.

You have a magic : first , you choose a interval [l,r],and then each Si(l<=i<=r) will be ( 10 – Si ) % 10.

You can use the magic at most once to make sum of all the numbers to be maximum.

What is the maximum sum you can get?

Input
First line of each case contains a number n.(1 ≤  n ≤ 1 000 000).

Next line contains n numbers without space-separated. Each position corresponds to a number of 0-9.
Output
Output the answer on a single line for each case.
Sample Input
10
3775053808
10
2580294019
10
4701956095
Sample Output
50
50
54
Hint

Source


代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int shu[1001000];
int main()
{
	char ch[1001000];
	int n;
	while (~scanf("%d",&n))
	{
		scanf("%s",ch);
		int s,p;
		s=0;
		for (int i=0;i<n;i++)
		{
			p=ch[i]-'0';
			s+=p;
			shu[i]=(10-p)%10-p;
		}
		int ss=0,ka=0;
		for (int i=0;i<n;i++)
		{
			ka+=shu[i];
			ss=max(ss,ka);
			if (ka<0)
			ka=0; 
		}
	if (ss>0)
	s+=ss; 
		printf("%d\n",s);
	}
	return 0;
 } 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值