JZ High School OJ 3404. [NOIP2013 simulation] Card Game

Description

Small X in order to show their superb skills of the game, one day happily find a small Y playing a card game. Each card has a type (attack or defense) and two power value information.

Small cards Y n-card, the small card X has the m. X known small cards that are all type of attack.

Each round of the game by the small X operating, first select a not used the card from his hand X. If you do not have the small Y card, the damage to the power of the value of X, otherwise little X to Y is selected from small hand a card Y. If Y is attacking (power only when the value of X is not less than the value of Y power optional), disappeared after the end of the current round of Y, Y small the damage is the difference between the power value of the power value of X and Y; if Y defensive type (power only when the value of X is greater than Y force value selectable), disappeared after the end of the current round of Y, Y does not hurt small.

X may end his small operation (cards do not have to run out) at any time. Smart hope you help him operate so that the total damage small Y at risk.
 

Input

First line of input contains two integers n and m.

The next n lines contains a string and an integer, respectively, of a small Y type of card ( "ATK" represents the attack, "DEF" represents defensive) and strength values.

Next m lines contains an integer that represents the power of a card value of X is small.

Output

Output line contains an integer representing the maximum total damage suffered by small Y.
 

Sample Input

Input. 1: 
2. 3
ATK 2000
the DEF 1700
2500
2500
2500

Input 2:
. 3. 4
ATK 10
ATK 100
ATK 1000
. 1
. 11
101
1001
 

Sample Output

Output 1: 
3000
[1] sample shows
the first round, small X to choose their first cards and small Y's second card, small Y's second card disappear.
The second round, small X to choose their second card and a small Y of the first card, the small card Y of the first to disappear, while being 500 damage.
The third round, small X to choose their third card, then the hands of small Y has no cards, by 2500 damage.
X small end of the game, the small Y 3000 were subject to damage.

Output 2:
992
[2] sample shows
the first round, small X to choose their third cards and small Y of the first card, the small card Y of the first to disappear, while being 91 points of damage.
The second round, small X to choose their own cards and fourth small Y's second card, the small card Y's second disappearance, at the same time by 901 points of damage.
X small end of the game, by a total of 992 small Y damage.
 
 

Data Constraint

Half of all sizes are small data satisfy Y only attack cards.

For 30% of the data, 1≤ n, m ≤ 6.

For 60% of the data, 1≤ n, m ≤10 ^ 3 .

To 100% of the data, 1≤ n, m ≤10 ^ 5 , the power values are non-negative integers not more than 10 ^ 6.
 1 #include <bits/stdc++.h>
 2 #define ll long long
 3 #define il inline
 4 #define rgi register ll
 5 
 6 using namespace std;
 7 
 8 const int oo = 0x3f3f3f3f;
 9 const ll N = 100000 + 10;
10 
11 ll n, m, step, ans, minn = oo;
12 ll def[N], atk[N], x[N];
13 ll sum_def[N], sum_atk[N], sum_x[N];
14 
15 il ll read()
16 {
17     rgi x = 0, f = 0, ch;
18     while(!isdigit(ch = getchar())) f |= ch == '-';
19     while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
20     return f ? -x : x;
21 }
22 
23 int main()
24 {
25     m = read(),n = read();
26     for(rgi i = 1; i <= m; ++i)
27     {
28         char op[10];
29         ll val;
30         scanf("%s %lld", op, &val);
31         if(op[0] == 'A')
32             atk[++atk[0]] = val;
33         else if(op[0] == 'D')
34             def[++def[0]] = val;
35     }
36     for(rgi i = 1; i <= n; ++i)
37         x[i] = read();
38     sort(atk + 1, atk + atk[0] + 1);
39     sort(def + 1, def + def[0] + 1);
40     sort(x + 1, x + n + 1);
41     for(rgi i = 1; i <= atk[0]; ++i)
42         sum_atk[i] = sum_atk[i - 1] + atk[i];
43     for(rgi i = 1; i <= def[0]; ++i)
44         sum_def[i] = sum_def[i - 1] + def[i];
45     for(rgi i = 1; i <= n; ++i)
46         sum_x[i] = sum_x[i - 1] + x[i];
47     atk[atk[0]+1] = oo;
48     for(rgi i = 1; i <= n; ++i)
49     {
50         while(x[i] >= atk[step])
51             step++;
52         step--;
53         minn = min(minn, step + n - i);
54     }
55     ans = sum_x[n] - sum_x[n - minn] - sum_atk[minn];
56     if(minn >= atk[0] && n > m)
57     {
58         step = 1;
59         for(rgi i = 1; i <= def[0]; ++i)
60         {
61             while(def[i] >= x[step])
62                 step++;
63             x[step] = 0;
64         }
65         if(step <= n - minn)
66             for(rgi i = 1; i <= n - minn; ++i)
67                 ans += x[i];
68     }
69     for(rgi i = 1; i < minn; ++i)
70         ans = max(ans, sum_x[n] - sum_x[n - i] - sum_atk[i]);
71     printf("%lld", ans);
72     return 0;
73 }

Guess you like

Origin www.cnblogs.com/anbujingying/p/11307968.html