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

#GD0000117. Thay đổi giá trị trên thẻ (Integer Cards)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Thay đổi giá trị trên thẻ (Integer Cards)

Integer Cards

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

There are NN cards with initial values AiA_i. For each of MM operations in order, you may choose at most BjB_j cards and overwrite their values with CjC_j. Cards may be rewritten multiple times. Maximize the final sum.

Input

The first line has N,MN,M, the second has NN values AiA_i, followed by MM lines with Bj,CjB_j,C_j.

Output

Print the maximum final sum of all cards.

Subtasks

  • Subtask 1 (20 points): 1≤N,M≤201\le N,M\le 20; 1≤Ai,Cj≤1091\le A_i,C_j\le10^9; 1≤Bj≤N1\le B_j\le N.
  • Subtask 2 (30 points): 1≤N,M≤10001\le N,M\le 1000; 1≤Ai,Cj≤1091\le A_i,C_j\le10^9; 1≤Bj≤N1\le B_j\le N.
  • Subtask 3 (50 points): 1≤N,M≤1000001\le N,M\le 100000; 1≤Ai,Cj≤1091\le A_i,C_j\le10^9; 1≤Bj≤N1\le B_j\le N.

Examples

Input

3 2
1 2 3
1 5
2 4

Output

13

Explanation

Replace the card worth 11 with 55, and the cards worth 22 and 33 with 44. The resulting values 5,4,45,4,4 sum to 1313.