REDONE Solution

Hi everyone, I need your help for solving this problem. Infact, I didn’t understand the meaning of this problem statement.

Problem code : REDONE

Problem Link

Thank you (in advance) and this is not an ongoing contest problem.

bro how to solve plus multiply i got tle

The solution is pretty trivial. Write the highest what you can get from n = 1 to 5, you will get the logic behind the problem.

Is it 719?

The problem says, that you have an array of length n. The array has numbers 1 to n appearing exactly once in any random order.
Eg:

  1. n = 5, a = [1, 2, 3, 4, 5]
  2. n = 5, a = [4, 3, 5, 1, 2]

Thus, you see the numbers can be arranged in any order. Now, you have to pick up two numbers (X and Y). Then append ((X + Y) + (X * Y)) into the array. Now delete those X and Y. You see the numbers are decreasing by 1. At the end, you will have a single number only. You have to find the maximum value of that number % 1e9 + 7.

so what does it mean, that the numbers can repeat later?

bro i didnot get how to solve

Yes, the numbers can repeat later and you can use same numbers as X and Y.

so What would be the possible output for n=4 and list is 1 2 3 4 4

Okay, the first one is a hint while the second one is the state.

Hint 1

The question is related to factorial series. Pre compute them.

Solution

Let n be the input.

Then,

fact[1] = 1;
fact[i] = fact[i - 1] * i;
ans = fact[n + 1] - 1;

You have to output the answer. Don’t forget about modulo 1e9 + 7.

Hope this helps, :slight_smile:.

The list contains n integers only, so no reputations are allowed when the list is made, after doing operations, numbers might repeat themselves. You can do operations on numbers which are equal too.

So when n = 4, the list can only be a permutation of [1, 2, 3, 4]

Okay so I have to consider only the values till n and no repetitions right?

Yes, absolutely correct. Natural numbers till n.

thank you .