Codeforces and Polygon may be unavailable from December 6, 19:00 (UTC) to December 6, 21:00 (UTC) due to technical maintenance. ×

Neev4321's blog

By Neev4321, history, 13 hours ago, In English

I am stuck on this problem.

Problem Synopsis:
You are given an array A of size N.
Consider an undirected edge-weighted graph with N nodes numbered from 1 to N such that for any two nodes i and j there is an undirected edge between i and j with weight |i-j| * max(A[i], A[j]).
Find the weight of the shortest path between two given nodes X and Y.

Input Format:
The first line contains a single integer T, the number of test cases.
The first line of each test case contains three integers N, X and Y.
The second line of each test case contains N integers, A[1] A[2] ... A[N].

Output Format
For each test case, print a single integer, the weight of the shortest path, on a separate line.

I have a working solution for the first 3 subtasks but have run out of ideas for the last one.
Any help would be appreciated.

my solution
  • Vote: I like it
  • +3
  • Vote: I do not like it