Programming contests

DEIK Regionális Programozó Csapatverseny, középiskolai kategória, 2023. december 3.

December 3, 2023, 10:00 AM – December 3, 2023, 3:30 PM

Vote

There’s an election in Peter’s city: two parties, A and B are fighting for power.

In the city there are NN districts, in the iith district there are ViV_i voters (i=1Ni=1\ldots N). By winning the iith district a party can delegate HiH_i members to the city council. You win the district if you have the majority of the votes in it and you win the election by delegating the majority of the members of the city council. It is known that for the iith district, that GiG_i golden coins are required for one voter to change his voting preferences. From opinion polls, we know that without any interference, in the iith district AiA_i people would vote for party A and BiB_i people would vote for party B (Vi=Ai+BiV_i=A_i+B_i). Peter wants Party A to win the election. Please calculate MM: the minimal amount of golden coins party A needs to spend to win the election.

Input specification

In the first line there is a number NN. Then NN lines follow with four numbers each - AiBiHiGiA_i\ B_i\ H_i\ G_i\ - describing the situation in the iith district (i=1N)(i=1\ldots N).

Output specification

A single line with the number MM

Constraints

1N1001\le N \le 100
1Ai,Bi1000001\le A_{i},\ B_{i} \le 100000
1Hi100001\le H_{i} \le 10000
1Gi1001\le G_{i} \le 100
Ai+BiisoddA_{i}+B_{i}\ \ \mathrm{is\ odd}
iHiisodd\sum_{i} H_{i}\ \ \mathrm{is\ odd}

Sample input 1

  1. 5
  2. 1 2 1 1
  3. 1 2 2 2
  4. 1 2 3 3
  5. 1 2 4 4
  6. 1 2 5 5
download as text file

Sample output 1

  1. 8
download as text file

Sample input 2

  1. 5
  2. 1 2 1 1
  3. 1 2 2 2
  4. 1 2 3 3
  5. 1 4 4 4
  6. 1 4 5 10
download as text file

Sample output 2

  1. 12
download as text file

Sample input 3

  1. 5
  2. 1 2 1 1
  3. 1 2 2 2
  4. 1 2 3 3
  5. 1 4 4 4
  6. 1 4 11 10
download as text file

Sample output 3

  1. 20
download as text file
University of Debrecen; Faculty of Informatics; v. 09/30/2024