Codeforces Round #115 A. Robot Bicorn Attack 暴力

时间:2023-03-09 06:32:31
Codeforces Round #115 A. Robot Bicorn Attack 暴力

A. Robot Bicorn Attack

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/175/problem/A

Description

Vasya plays Robot Bicorn Attack.

The game consists of three rounds. For each one a non-negative integer amount of points is given. The result of the game is the sum of obtained points. Vasya has already played three rounds and wrote obtained points one by one (without leading zeros) into the string s. Vasya decided to brag about his achievement to the friends. However, he has forgotten how many points he got for each round. The only thing he remembers is the string s.

Help Vasya to find out what is the maximum amount of points he could get. Take into account that Vasya played Robot Bicorn Attack for the first time, so he could not get more than 1000000 (106) points for one round.

Input

The only line of input contains non-empty string s obtained by Vasya. The string consists of digits only. The string length does not exceed 30 characters.

Output

Print the only number — the maximum amount of points Vasya could get. If Vasya is wrong and the string could not be obtained according to the rules then output number -1.

Sample Input

1234

Sample Output

37

HINT

题意

给你一个字符串,要求使得字符串分为3节,并且每节都不能带首位0

并且每一节的数字都不能超过1e6

问你这三节的和最大可能为多少

题解:

暴力咯,数据范围只有30~

不过这道题如果数据范围出到1e5的话,是一道非常好玩的题目哦~

代码:

#include<iostream>
#include<stdio.h>
using namespace std; string s;
long long ans = ;
long long solve(int l,int r)
{
if(l!=r&&s[l]=='')return -;
long long res = ;
for(int i=l;i<=r;i++)
{
res = res * + (s[i]-'');
if(res>)
return -;
}
return res;
}
int main()
{
cin>>s;
int flag = ;
for(int i=;i<s.size();i++)
{
for(int j=i+;j<s.size();j++)
{
long long sum1 = solve(,i-);
long long sum2 = solve(i,j-);
long long sum3 = solve(j,s.size()-);
if(sum1==-||sum2==-||sum3==-)
continue;
ans = max(ans,sum1+sum2+sum3);
flag = ;
}
}
if(flag==)
return puts("-1");
printf("%d\n",ans);
}