Connection Status:
Competition Arena > NumReverseEasy
SRM 855 · 2024-05-22 · by misof · Brute Force, Simple Math
Class Name: NumReverseEasy
Return Type: long
Method Name: getsum
Arg Types: (int, int)
Problem Statement

Problem Statement

Take all the positive integers from A to B, inclusive.

Reverse as many of them as you like. (E.g., reversing 1234 changes it into 4321, and reversing 4700 turns it into 0074 = 74.)

Then, add them all up.

Calculate and return the largest possible result you can get.

Constraints

  • B will be between 1 and 100,000, inclusive.
  • A will be between 1 and B, inclusive.
Examples
0)
21
23
Returns: 75

We have the numbers 21, 22, and 23. We can reverse 23 to get 32. This will give us the final sum 21 + 22 + 32 = 75, which is the largest result we can get from these three numbers.

1)
12
21
Returns: 489

Note that after we reverse 12, our collection of numbers will contain two separate 21s. Each of them contributes to the final sum.

2)
97
101
Returns: 495

Here an optimal solution is not to reverse anything.

3)
123
127
Returns: 2605

Here an optimal strategy is to reverse everything.

4)
1
100000
Returns: 6226873030

Watch out for integer overflow.

Submissions are judged against all 11 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class NumReverseEasy with a public method long long getsum(int A, int B) · 11 test cases · 2 s / 256 MB per case

Submitting as anonymous