Codeforces Round 366 (Div. 1)
D
Captain America
Codeforces
3100
原题
← CE →
翻译中…

Steve Rogers is fascinated with new vibranium shields S.H.I.E.L.D gave him. They're all uncolored. There are $*n*$ shields in total, the $*i*$-th shield is located at point $(*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 $*r*$ dollars while painting it in blue costs $*b*$ dollars.

翻译中…

Additionally, there are $*m*$ constraints Steve wants to be satisfied. The $*i*$-th constraint is provided by three integers $*t*_{*i*}$, $*l*_{*i*}$ and $*d*_{*i*}$:

翻译中…
  • If $*t*_{*i*} = 1$, then the absolute difference between the number of red and blue shields on line $*x* = *l*_{*i*}$ should not exceed $*d*_{*i*}$.
  • If $*t*_{*i*} = 2$, then the absolute difference between the number of red and blue shields on line $*y* = *l*_{*i*}$ should not exceed $*d*_{*i*}$.
翻译中…

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

翻译中…

Input

翻译中…

The first line of the input contains two integers $*n*$ and $*m*$ ($1 ≤ *n*, *m* ≤ 100 000$) — the number of shields and the number of constraints respectively.

翻译中…

The second line contains two integers $*r*$ and $*b*$ ($1 ≤ *r*, *b* ≤ 10^{9}$).

翻译中…

The next $*n*$ lines contain the shields coordinates. The $*i*$-th of these lines contains two integers $*x*_{*i*}$ and $*y*_{*i*}$ ($1 ≤ *x*_{*i*}, *y*_{*i*} ≤ 10^{9}$).

翻译中…

The next $*m*$ lines contain the constrains. The $*j*$-th of these lines contains three integers $*t*_{*j*}$, $*l*_{*j*}$ and $*d*_{*j*}$ ($1 ≤ *t*_{*j*} ≤ 2, 1 ≤ *l*_{*j*} ≤ 10^{9}, 0 ≤ *d*_{*j*} ≤ *n*$).

翻译中…

Output

翻译中…

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 $*n*$ consisting of letters 'r' and 'b' only. The $*i*$-th character should be 'r' if the $*i*$-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.

翻译中…

样例

Input #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
Output #1
25
rbrbb
InputCopy OutputCopy
Input #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
Output #2
-1
InputCopy OutputCopy
题目信息
题号
704D
时间限制
2 s
内存限制
256 MB
标签
网络流
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。