Disjoint-Sparse-Table Optimization

시간 제한2초메모리 제한1024 MB

요약
1부터 2Q까지의 점을 잇는 Q개의 구간과 가중치 배열이 주어질 때, 각 구간을 직접 사거나 내부 한 점에서 두 구간으로 쪼개 사는 조건을 만족하는 최소 비용 집합을 찾는다.
난이도

어려움10점 중 8점

유형
동적 계획법, 구간, 분할 정복
정답자
아직 제출이 없습니다

문제

You are given an integer sequence AA of length 2Q−12Q-1 and QQ intervals \[L_i,R_i)\[L\_i, R\_i). Here, L_iL\_i, R_iR\_i satisfy L_i<R_iL\_i < R\_i, and each integer between 11 and 2Q2Q appears once as an end of an interval.

Your goal is to create a set SS of intervals to satisfy at least one of the following conditions for all i=1,2,…,Qi = 1, 2, \dots, Q.

  • \[L_i,R_i)∈S\[L\_i, R\_i) \in S
  • There exists an integer xx (L_i<x<R_iL\_i < x < R\_i) such that \[L_i,x)∈S\[L\_i, x) \in S and \[x,R_i)∈S\[x, R\_i) \in S.

The cost of the set SS is defined as follows.

The sum of A_l+A_l+1+⋯+A_r−1A\_l + A\_{l+1} + \dots + A\_{r-1} for all intervals \[l,r)\[l,r) included in SS.

Find the minimum cost of the set that satisfies the condition.

입력

QQ

L_1L\_1 R_1R\_1

⋮\vdots

L_QL\_Q R_QR\_Q

A_1A\_1 A_2A\_2 …\dots A_2Q−1A\_{2Q-1}

출력

Output the minimum cost of the set that satisfies the condition. Add a new line at the end of the output.

제한

  • All inputs consist of integers.
  • 1≤Q≤1001 \le Q \le 100
  • 1≤L_i<R_i≤2Q1 \le L\_i < R\_i \le 2Q
  • Each integer from 11 to 2Q2Q appears in L_1,…,L_Q,R_1,…,R_QL\_1, \dots, L\_Q, R\_1, \dots, R\_Q.
  • 1≤A_i≤1091 \le A\_i \le 10^9

힌트

In Sample Input 1, the optimal set is S=\[1,4),\[2,3),\[3,5),\[5,6)S = \\{\[1, 4), \[2, 3), \[3, 5), \[5, 6)\\}, where the cost is y+2+7+5=20y + 2+7+5=20.

예제2

  1. 예제 1

    입력
    3
    1 4
    2 5
    3 6
    1 2 3 4 5
    
    예상 출력
    20
    
  2. 예제 2

    입력
    5
    3 7
    1 10
    5 9
    4 8
    2 6
    6 4 8 5 9 8 9 8 2
    
    예상 출력
    132