Function and Queries
Time limit2sMemory limit512 MB
Given an array and a recurrence f(i,j)=min(f(i-1,j),f(i-1,j-1))+a_j, answer up to 1e5 offline queries for f(x,y).
- Level
Hard9 of 10
- Topics
- Dynamic programming, Divide and conquer, Math, Combinatorics
- Solved
- No attempts yet
Problem
You are given an array of length . The function is defined as follows.
You are also given queries. Each query consists of two integers and , and asks for the value of . Write a program that answers every query.
Input
The first line contains the size of the array ().
The second line contains separated by spaces. ()
The third line contains the number of queries (). Each of the next lines contains one query as and . ()
Output
Print the value of for each query, one per line, in the order the queries are given.