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.
I found the solution (which surprisingly, builds upon the last solution)!
Leaving this here for anyone also searching for the solution.
Hello, Did you come up with any solution to solve Problem B: Two Arrays of the same contest? I would like to know your approach.
I used DP (dynamic programming) with the recurrence:
This recurrence can be simplified to: