武大校赛资格赛 差值维护

Problem 1565 - B - Magic
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

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long LL;
const int INF = 0x4fffffff;
const double EXP = 1e-5;
const int MS = 1000005;
const int SIZE = 100005;

int num[MS];
int s[MS];
char str[MS];

int main()
{
      int n;
    while(cin>>n)
    {
        //  cin>>n;
      cin>>str;
      int sum=0;
      int ans=0;
      int total=0;
    // s[0]=0;
  //  int ss,tt;
      for(int i=0;i<n;i++)
      {
            //num[i]=10-(2*(str[i]-'0'));

            num[i]=(10-(str[i]-'0'))%10;
            num[i]=num[i]-(str[i]-'0');
          //  s[i+1]=s[i]+str[i]-'0';
            total+=str[i]-'0';
            if(sum<=0)
            {
                  sum=num[i];
                  //ss=i;
            }
            else
                  sum+=num[i];
            if(sum>ans)
            {
                  ans=sum;
                // tt=i;
            }
      }
    // cout<<ans<<endl;

      //cout<<ss<<"  "<<tt<<endl;

      cout<<total+ans<<endl;

    }





      return 0;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值