Problemas
There are a total of
At Farmer John's signal, some of the cows will form pairs such that
Every pair consists of a Holstein
h and a Guernseyg whose locations are withinK of each other (1≤K≤10^9 ); that is,|x_h−x_g|≤K .Every cow is either part of a single pair or not part of a pair.
The pairing is maximal; that is, no two unpaired cows can form a pair.
It's up to you to determine the range of possible sums of weights of the unpaired cows. Specifically,
If
T=1 , compute the minimum possible sum of weights of the unpaired cows.If
T=2 , compute the maximum possible sum of weights of the unpaired cows.
Entrada
The first input line contains
Following this are
Salida
The minimum or maximum possible sum of weights of the unpaired cows.
Ejemplo #1
2 5 4
G 1 1
H 3 4
G 4 2
H 6 6
H 8 9
16
Cows
Ejemplo #2
1 5 4
G 1 1
H 3 4
G 4 2
H 6 6
H 8 9
6
Cows
Ejemplo #3
2 10 76
H 1 18
H 18 465
H 25 278
H 30 291
H 36 202
G 45 96
G 60 375
G 93 941
G 96 870
G 98 540
1893