武大校赛资格赛 差值维护

来源:互联网 发布:mysql可以不要主键吗 编辑:程序博客网 时间:2024/06/10 03:02
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;}


 

0 0