Paint Rooms X63503


Statement
 

pdf   zip

Leonardo was walking in Rome, where a lot of emblematic buildings were not maintained at all, so he decided to start a new business for tourism promotion, earning as much money as possible within a limited time window.

How many rooms can Leonardo paint in a workday? Luca Pacioli, a good old friend of Leonardo, helped him to extract the formula of the required time, where Luca said: "You are a really fast painter, so you just need 1 minute per square meter".

Given the time Leonardo has to paint the rooms, the width and height of a wall and taking into account each room has 4 similar walls and the roof, and the money Leonardo can earn for each room, print the maximum amount of money Leonardo can earn.

Input

The input consists of several test cases. Each test case consists of a total time TT where 50T100050 \leq T \leq 1000, the number of rooms RR such that 1R10001\leq R\leq 1000, and the next RR lines have the width wiw_i and height hih_i of a wall of the room rir_i, and the money mim_i Leonardo earns painting the ii-th room.

Output

For each test case, return the maximum amount of money Leonardo can earn painting rooms.

Public test cases
  • Input

    80 3
    2 5 17
    1 2 15
    3 2 16
    
    96 4
    4 1 10
    4 1 10
    4 1 10
    4 5 31
    
    96 4
    4 1 11
    4 1 11
    4 1 11
    4 5 31
    

    Output

    33
    31
    33
    
  • Information
    Author
    Javier Segovia
    Language
    English
    Official solutions
    Unknown.
    User solutions
    C++