Can someone please help me out to understand the solution of 340 C -- TOURIST PROBLEM solution given below:

THANKS IN ADVANCE :)

# | User | Rating |
---|---|---|

1 | tourist | 3645 |

2 | Radewoosh | 3403 |

3 | Um_nik | 3348 |

4 | LHiC | 3336 |

5 | Benq | 3316 |

6 | V--o_o--V | 3275 |

7 | mnbvmar | 3241 |

8 | yutaka1999 | 3190 |

9 | ainta | 3180 |

10 | Petr | 3106 |

# | User | Contrib. |
---|---|---|

1 | Errichto | 191 |

2 | Radewoosh | 177 |

3 | rng_58 | 164 |

4 | PikMike | 162 |

5 | Vovuh | 160 |

6 | majk | 158 |

7 | 300iq | 154 |

8 | antontrygubO_o | 153 |

9 | Um_nik | 151 |

10 | kostka | 149 |

Codeforces (c) Copyright 2010-2019 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Aug/19/2019 18:11:23 (e2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

Why are you sending a link to the C ++ code in the Java platform?)

Secondly, there is a problem analysis and officially the correct solution: Click

Good luck!

Hey!

To solve this problem you can read the

EDITORIALHERE, you can also see the writer's solution HERE.Now after you're done understanding the solution, let's answer your question, as in the writer's solution, you can find that the

numerator (sumtot)is the next: (please notice that the indices in the writer's solution start from 1, while in the next few lines I will start them from 0 as in the solution you are asking about)`sumtot = sum1 + 2 * sum2`

->

`sum1 = x[0] + x[1] + ... + x[n-1]`

->

`sum2 = (x[0]*0-0)+(x[1]*1-x[0])+(x[2]*2-x[1]-x[0]) +...+ (x[n-1]*(n-1)-x[n-2]-x[n-3]-...-x[0])`

Now you can find the next for every

`x[i] ; {0 <= i <= n-1}`

:`**sumtot[i]** = x[i] + 2 * { i - ( n - 1 - i ) } * x[i]`

->

`sumtot[i] = x[i] + 2 ( 2 * i + 1 - n ) * x[i]`

->

`sumtot[i] = x[i] * ( 3 + 4 * i - 2 * n )`

And finally,

`sumtot = SUM of all sumtot[i]`

hope every thing is clear now :)

yeah!! :)