CF1866E.Elevators of Tamem

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

There is a building named Taman Membeku (shortened as Tamem). The building has NN floors numbered from 11 to NN from bottom to top. The only way to move between floors in the building is to use elevators. There are 33 elevators available in Tamem, namely elevators 11 , 22 , and 33 .

Pak Chanek works as an elevator operator in Tamem. Pak Chanek will work for QQ days. Initially, each elevator is in floor 11 and all elevators are on. On each day, exactly one of the following will happen:

  • 1 x y – There is a person currently in floor xx who wants to go to floor yy . ( 1x,yN1\leq x,y\leq N ; xyx\neq y )
  • 2 p – Elevator pp changes state at the start of the day. If previously it is on, then it will turn off. If previously it is off, then it will turn on. ( 1p31\leq p\leq3 )

For each day, Pak Chanek can control the movement of all elevators as he pleases. However, for each day where there is a person currently in floor xx who wants to go to floor yy , among all elevator movements done by Pak Chanek, the following must happen:

  1. One elevator moves to floor xx .
  2. The person gets into the elevator.
  3. The elevator moves to floor yy .
  4. The person gets out of the elevator.

For each day, Pak Chanek can only move the elevators that are currently on. Note that, since a change in state happens at the start of the day, this means that an elevator that turns off on some day starts becoming unusable from that day itself. Conversely, an elevator that turns on on some day starts becoming usable from that day itself.

It is known that the electricity fee for each day is different. More specifically, on the jj -th day, the fee needed to move one elevator up or down by one floor is AjA_j .

From the start, Pak Chanek already knows the electricity fees and the sequence of events that will happen on the QQ days, so Pak Chanek can operate the elevators strategically. What is the minimum possible electricity fee to fulfill all needs of the people who want to move between floors in Tamem? Note: in the end, each elevator does not have to go back to floor 11 .

输入格式

The first line contains two integers NN and QQ ( 2N1052\leq N\leq10^5 ; 1Q3001\leq Q\leq300 ) — the number of floors and the number of days.

The second line contains QQ integers A1,A2,A3,AQA_1, A_2, A_3 \ldots, A_Q ( 1Aj1051 \leq A_j \leq 10^5 ) — the electricity fee for each day.

The jj -th of the next QQ lines contains the jj -th event as described. At any moment, there will always be at least one elevator that is on.

输出格式

An integer representing the minimum possible electricity fee to fulfill all needs of the people who want to move between floors in Tamem.

输入输出样例

  • 输入#1

    9 8
    3 4 4 3 4 2 7 6
    1 2 7
    1 3 9
    2 2
    1 4 5
    1 3 5
    2 2
    1 7 3
    1 2 1

    输出#1

    114

说明/提示

The following is an example of an optimal strategy:

  1. On the 11 -st day:
  • Elevator 22 moves to floor 33 .
  • Elevator 33 moves to floor 22 , picks the person up, moves to floor 77 , then drops the person off.
  1. On the 22 -nd day:
  • Elevator 22 picks the person up, moves to floor 99 , then drops the person off.
  1. On the 33 -rd day:
  • Elevator 22 turns off.
  1. On the 44 -th day:
  • Elevator 33 moves to floor 44 , picks the person up, moves to floor 55 , drops the person off, then moves to floor 33 .
  1. On the 55 -th day:
  • Elevator 33 picks the person up, moves to floor 55 , then drops the person off.
  1. On the 66 -th day:
  • Elevator 22 turns on.
  • Elevator 11 moves to floor 22 .
  • Elevator 22 moves to floor 77 .
  1. On the 77 -th day:
  • Elevator 22 picks the person up, moves to floor 33 , then drops the person off.
  1. On the 88 -th day:
  • Elevator 11 picks the person up, moves to floor 11 , then drops the person off.

The total electricity fee for each day from the 11 -st day to the 88 -th day are 2424 , 2424 , 00 , 1818 , 88 , 66 , 2828 , and 66 respectively. Therefore, the total electricity fee for the entire QQ days is 24+24+0+18+8+6+28+6=11424+24+0+18+8+6+28+6=114 .

It can be obtained that there is no strategy that requires a smaller electricity fee.

首页