PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BF0000044. Đốt trại liên hoàn (Burn the Linked Camp)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đốt trại liên hoàn (Burn the Linked Camp)

Burn the Linked Camp

Source: ZOJ

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn successive camps. Camp ii contains an integer number of soldiers from 00 to CiC_i. Each observation (l,r,k)(l,r,k) requires at least kk soldiers in camps ll through rr. Find the minimum total, or output Bad Estimations if contradictory.

Input

First line n,mn,m, then nn capacities CiC_i, then mm triples l,r,kl,r,k.

Output

Print the minimum total soldiers, or exactly Bad Estimations.

Subtasks

  • Subtask 1 (20 points): 1≤n≤121\le n\le12, 0≤m≤300\le m\le30; 0≤Ci≤1060\le C_i\le10^6; 1≤l≤r≤n1\le l\le r\le n; 0≤k<2310\le k<2^{31}.
  • Subtask 2 (30 points): 1≤n≤1501\le n\le150, 0≤m≤8000\le m\le800; 0≤Ci≤1060\le C_i\le10^6; 1≤l≤r≤n1\le l\le r\le n; 0≤k<2310\le k<2^{31}.
  • Subtask 3 (50 points): 1≤n≤10001\le n\le1000, 0≤m≤100000\le m\le10000; 0≤Ci≤1060\le C_i\le10^6; 1≤l≤r≤n1\le l\le r\le n; 0≤k<2310\le k<2^{31}.

Examples

Input

3 2
1000 2000 1000
1 2 1100
2 3 1300

Output

1300

Explanation

The constraints require a1+a2≥1100a_1+a_2\ge1100 and a2+a3≥1300a_2+a_3\ge1300, so the total is at least 13001300. The allocation (0,1100,200)(0,1100,200) stays within capacities and meets both observations. Hence the optimum is 13001300.