CF115E.Linear Kingdom Races

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are a car race organizer and would like to arrange some races in Linear Kingdom.

Linear Kingdom has nn consecutive roads spanning from left to right. The roads are numbered from 11 to nn from left to right, thus the roads follow in the order of their numbers' increasing. There will be several races that may be held on these roads. Each race will use a consecutive subset of these roads. Also, each race will pay some amount of money to you if this race is held. No races overlap in time, so some roads can be used in several races.

Unfortunately, some of the roads are in a bad condition and they need repair. Each road has repair costs associated with it, you are required to pay this cost to repair the road. A race can only take place if all the roads used in the race are renovated. Your task is to repair such roads (possibly all or none) that will maximize your profit. Your profit is defined as the total money you get from the races that are held minus the total money you spent to repair the roads. Note that you may decide not to repair any road and gain zero profit.

Print the maximum profit you can gain.

输入格式

The first line contains two single-space separated integers, nn and mm ( 1<=n,m<=21051<=n,m<=2·10^{5} ), denoting the number of roads and the number of races, respectively.

Then nn lines follow, each line will contain a single non-negative integer not exceeding 10910^{9} denoting the cost to repair a road. The costs are given in order from road 11 to road nn .

Finally, mm lines follow. Each line is single-space-separated triplets of integers. Each triplet will be given as lblb , ubub , and pp ( 1<=lb<=ub<=n,1<=p<=1091<=lb<=ub<=n,1<=p<=10^{9} ), which means that the race these three integers describe will use all the roads from lblb to ubub , inclusive, and if it's held you get pp .

输出格式

Print a single integer denoting the maximum possible profit you can gain.

Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is recommended to use cin, cout stream (also you may use %I64d specificator).

输入输出样例

  • 输入#1

    7 4
    3
    2
    3
    2
    1
    2
    3
    1 2 5
    2 3 5
    3 5 3
    7 7 5
    

    输出#1

    4
    
  • 输入#2

    2 1
    0
    3
    1 2 5
    

    输出#2

    2
    
  • 输入#3

    3 1
    10
    10
    10
    1 3 10
    

    输出#3

    0
    

说明/提示

In the first sample the optimal solution is to repair roads 11 , 22 , 33 , and 77 . Three races will take place which nets you 1515 . The road repair costs 1111 , hence your profit is 44 .

首页