luogu#P7955. [COCI 2014/2015 #6] NIKO

[COCI 2014/2015 #6] NIKO

Background

In 2018, in Russia, the 21st World Cup.

Problem Description

For convenience, let O\tt O represent a defensive player, V\tt V represent a midfielder, and N\tt N represent an attacking player.

The coach has several formation plans OVNO-V-N, where O,V,NO,V,N are the counts of O,V,N\tt O,V,N respectively. Of course, it must hold that O+V+N=10O+V+N=10.

Now, each of the mm players can play some of the roles among O,V,N\tt O,V,N. The coach wants to know whether each of his formation plans can be achieved.

Input Format

The first line contains an integer nn, indicating the number of the coach's plans.

The next nn lines each contain three integers Oi,Vi,NiO_i,V_i,N_i, describing each plan.

The next line contains an integer mm, indicating the number of players.

The next mm lines describe the roles that each player can play.

Output Format

Output nn lines in total.

  • If the ii-th plan can be satisfied, output DA on the ii-th line.
  • Otherwise, output NE.
2
4-4-2
10-0-0
10
O
O
O
O
O
O
O
O
ON
NO
NE
DA
3
4-4-2
3-5-2
4-3-3
11
OV
OV
OVN
OV
OV
V
V
N
O
O
O
DA
DA
NE

Hint

Explanation for Sample 1

Obviously, the coach can only use 10-0-0.

Explanation for Sample 2

  • For 4-4-2, players 1,2,9,101,2,9,10 can be assigned as O\tt O, players 4,5,6,74,5,6,7 can be assigned as V\tt V, and players 3,83,8 can be assigned as N\tt N.
  • For 3-5-2, players 4,9,104,9,10 can be assigned as O\tt O, players 1,2,5,61,2,5,6 can be assigned as V\tt V, and players 3,83,8 can be assigned as N\tt N.
  • For 4-3-3, it is impossible, because only 22 players can be N\tt N.

Constraints

For 100%100\% of the testdata, 1n101\le n\le 10, 10m2210\le m\le 22.

Notes

According to the original configuration, the full score is 80 points.

Translated from COCI 2014-2015 Contest #6 Task B NIKO.

Translated by ChatGPT 5