Neev4321's blog

By Neev4321, history, 3 weeks 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

Full text and comments »

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

By Neev4321, history, 6 weeks ago, In English

I recently came across this blog post and decided to try some of its problems. I am stuck on this problem. I can think of a naive O(n^2) solution by iterating through all pairs but do not see any redundancy in this solution. I cannot see a way to make it sub-quadratic (other than using the fact that 1 ≤ ai ≤ 2.5 * 10^6, maybe?). Any hints would be appreciated.

Full text and comments »

  • Vote: I like it
  • +1
  • Vote: I do not like it