Connection Status:
Competition Arena > AveragesOfThree
SRM 843 · 2023-01-03 · by misof · Simple Math
Class Name: AveragesOfThree
Return Type: int[]
Method Name: restore
Arg Types: (vector<int>)
Problem Statement

Problem Statement

There was a sequence A that had at least three elements.

The sequence B was obtained by writing down the average of each three consecutive elements of A, from left to right.


For example, if A = {a, b, c, d, e}, then the sequence B would have the form {f, g, h} where f = the average of a,b,c, g = the average of b,c,d, and h = the average of c,d,e.


You are given the sequence B. All its elements are integers. You are also given the information that the first two elements of A were zeros.

Reconstruct A and return it.

Notes

  • The sequence A is always unique.
  • For the given constraints it is guaranteed that all elements of A are integers that fit into signed 32-bit integer variables.

Constraints

  • B will have between 1 and 10 elements, inclusive.
  • Each element of B will be between 0 and 1000, inclusive.
Examples
0)
{3}
Returns: {0, 0, 9 }

The original sequence was {0, 0, x}, and as the average of 0, 0, and x was 3, it is clear that x must have been 9.

1)
{1, 3, 6, 5}
Returns: {0, 0, 3, 6, 9, 0 }
2)
{3, 1, 4, 1, 5, 9, 2, 6}
Returns: {0, 0, 9, -6, 9, 0, 6, 21, -21, 18 }

As seen here, some elements of the original sequence may be negative integers.

3)
{64, 440, 566, 464, 584, 351}
Returns: {0, 0, 192, 1128, 378, -114, 1488, -321 }
4)
{524, 395, 401, 630, 41}
Returns: {0, 0, 1572, -387, 18, 2259, -2154 }

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

Coding Area

Language: C++17 · define a public class AveragesOfThree with a public method vector<int> restore(vector<int> B) · 56 test cases · 2 s / 256 MB per case

Submitting as anonymous