Editorial for COCI '14 Contest 6 #2 Niko


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Let us denote the set of players that can only play defense by o, the set of players that can only play midfield positions by v, and the set of players that can only play offense by n. Let us denote the set of players that can play both defense and offense by on. Analogously, we have ov and vn. Finally, let us denote the set of players that can play all three lines by ovn.

For a given formation O-V-N, it is necessary to carefully come up with a layout of the players. We will obviously place the players from sets o, v and n on the lines they can play in. The problem arises when we don't have enough defensive players and need to decide whether to take players that can play both defense and midfield positions or those that can play both defense and offense.

As it usually is with programming, we don't need to make a decision, we can try out all possible combinations and see which one is best.

  • Let a be the number of players from set on we will put into defense. Then on-a players from that set will go into offense.
  • Let b be the number of players from set vn we will put into midfield positions. Then vn-b players from that set will go into offense.
  • Let c be the number of players from set ov we will put into offense. Then ov-c players from that set will go into midfield positions.

Now we are missing only O-o-a-c players in defense, V-b-(ov-c) players in midfield positions and N-(on-a)-(vn-b) players in offense. Therefore, the layout is possible only if ovn is larger than or equal to the sum of those three numbers.

Now it is enough to try all possible combinations for numbers a, b and c and output DA if a layout works out, and NE if there isn't a possible layout.


Comments

There are no comments at the moment.