CF254E.Dormitory

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Student Vasya came to study in Berland State University from the country, so he is living in a dormitory. A semester has nn days, and in each of those days his parents send him some food. In the morning of the ii -th day he receives aia_{i} kilograms of food that can be eaten on that day and on the next one (then the food goes bad and becomes unfit for consumption).

Every day Vasya eats vv kilograms of food. It is known that Vasya's parents do not allow him to starve, so there always is enough food for Vasya. Vasya has mm friends who sometimes live with him. Let's index the friends from 1 to mm . Friend number jj lives with Vasya from day ljl_{j} to day rjr_{j} , inclusive. Also, the jj -th friend requires fjf_{j} kilograms of food per day. Usually Vasya's friends eat in the canteen, but sometimes generous Vasya feeds some of them. Every day Vasya can feed some friends who live with him this day (or may feed nobody).

Every time Vasya feeds his friend, he gives him as much food as the friend needs for the day, and Vasya's popularity rating at the University increases by one. Vasya cannot feed the same friend multiple times in one day. In addition, he knows that eating habits must be regular, so he always eats vv kilograms of food per day.

Vasya wants so choose whom he will feed each day of the semester to make his rating as high as possible. Originally Vasya's rating is 0 because he is a freshman.

输入格式

The first line contains two integers nn and vv ( 1<=n,v<=4001<=n,v<=400 ). The second line contains nn integers a1,a2,...,ana_{1},a_{2},...,a_{n} ( 1<=ai<=4001<=a_{i}<=400 ), separated by single spaces. Value aia_{i} means that in the morning of the ii -th day aia_{i} kilograms of food come, the food is good for eating on day ii and/or on day i+1i+1 (then the food goes bad). It is guaranteed that if Vasya doesn't feed anyone, there is a way for him to eat so as to consume vv kilograms of food every day.

The third line contains integer mm ( 1<=m<=4001<=m<=400 ). Each of the following mm lines describes one Vasya's friend: the jj -th of these lines contains three integers lj,rj,fjl_{j},r_{j},f_{j} ( 1<=lj<=rj<=n,1<=fj<=4001<=l_{j}<=r_{j}<=n,1<=f_{j}<=400 ), separated by single spaces.

输出格式

In the first line print the highest rating Vasya can reach. In the next nn lines print, which friends Vasya needs to feed on each day. In the ii -th of these lines first print the number of friends to feed on the ii -th day, and then list the indexes of these friends. Print the friends in these lists in any order. If there are multiple optimal solutions, print any of them.

输入输出样例

  • 输入#1

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

    输出#1

    7
    1 2
    1 2
    3 2 1 3
    2 2 3
    
首页