CF704D.Captain America

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Steve Rogers is fascinated with new vibranium shields S.H.I.E.L.D gave him. They're all uncolored. There are nn shields in total, the ii -th shield is located at point (xi,yi)(x_{i},y_{i}) of the coordinate plane. It's possible that two or more shields share the same location.

Steve wants to paint all these shields. He paints each shield in either red or blue. Painting a shield in red costs rr dollars while painting it in blue costs bb dollars.

Additionally, there are mm constraints Steve wants to be satisfied. The ii -th constraint is provided by three integers tit_{i} , lil_{i} and did_{i} :

  • If ti=1t_{i}=1 , then the absolute difference between the number of red and blue shields on line x=lix=l_{i} should not exceed did_{i} .
  • If ti=2t_{i}=2 , then the absolute difference between the number of red and blue shields on line y=liy=l_{i} should not exceed did_{i} .

Steve gave you the task of finding the painting that satisfies all the condition and the total cost is minimum.

输入格式

The first line of the input contains two integers nn and mm ( 1<=n,m<=1000001<=n,m<=100000 ) — the number of shields and the number of constraints respectively.

The second line contains two integers rr and bb ( 1<=r,b<=1091<=r,b<=10^{9} ).

The next nn lines contain the shields coordinates. The ii -th of these lines contains two integers xix_{i} and yiy_{i} ( 1<=xi,yi<=1091<=x_{i},y_{i}<=10^{9} ).

The next mm lines contain the constrains. The jj -th of these lines contains three integers tjt_{j} , ljl_{j} and djd_{j} ( 1<=tj<=2,1<=lj<=109,0<=dj<=n1<=t_{j}<=2,1<=l_{j}<=10^{9},0<=d_{j}<=n ).

输出格式

If satisfying all the constraints is impossible print -1 in first and only line of the output.

Otherwise, print the minimum total cost in the first line of output. In the second line print a string of length nn consisting of letters 'r' and 'b' only. The ii -th character should be 'r' if the ii -th shield should be painted red in the optimal answer and 'b' if it should be painted blue. The cost of painting shields in these colors should be equal the minimum cost you printed on the first line.

If there exist more than one optimal solution, print any of them.

输入输出样例

  • 输入#1

    5 6
    8 3
    2 10
    1 5
    9 10
    9 10
    2 8
    1 9 1
    1 2 1
    2 10 3
    2 10 2
    1 1 1
    2 5 2
    

    输出#1

    25
    rbrbb
    
  • 输入#2

    4 4
    7 3
    10 3
    9 8
    10 3
    2 8
    2 8 0
    2 8 0
    1 2 0
    1 9 0
    

    输出#2

    -1
    
首页