三种选法,
C
+
D
C + D
C+D /
D
+
D
D + D
D+D /
C
+
C
C + C
C+C
C
+
D
C + D
C+D : 两者都要有
D
+
D
D + D
D+D /
C
+
C
C + C
C+C : 至少有两个
m
x
[
i
]
mx[i]
mx[i] : 在
i
i
i 前最大的
b
e
a
u
t
i
f
u
l
beautiful
beautiful
c
c
cc
cc /
d
d
dd
dd : 存储
P
I
I
PII
PII 类型的数据,按照
p
r
i
c
e
price
price 排序
细节注释
AC(sorting)
#include <bits/stdc++.h>
using namespace std;
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
typedef pair<int, int> PII;
typedef vector<int> VI;
const int N = 1e5 + 10;
vector<PII> cc, dd;
int mx[N];
int work(vector<PII> &t, int st) {
int len = t.size();
memset(mx, 0, sizeof mx);
for (int i = 1; i <= len; i ++ )
mx[i] = max(mx[i - 1], t[i - 1].SE); // 注释1
int p = 0;
int ans = 0;
for (int i = len - 1; i >= 0; i -- ) { //注释2
while (p < i && t[i].FI + t[p].FI <= st) //注释3
p ++;
p = min(p, i); //注释3
if (p > 0) ans = max(ans, mx[p] + t[i].SE); //注释4
}
return ans;
}
int main() {
int n, c, d;
int sum1 = 0, sum2 = 0, sum3 = 0;
scanf("%d%d%d", &n, &c, &d);
int tmp1 = 0, tmp2 = 0;
for (int i = 1; i <= n; i ++ ) {
int b, p;
char ch[2];
scanf("%d%d%s", &b, &p, ch);
if (ch[0] == 'C' && p <= c) {
cc.PB(MP(p, b));
tmp1 = max(tmp1, b);
} else if (ch[0] == 'D' && p <= d) {
dd.PB(MP(p, b));
tmp2 = max(tmp2, b);
}
}
sort(cc.begin(), cc.end());
sort(dd.begin(), dd.end());
int ans = 0;
if (cc.size() && dd.size()) ans = tmp1 + tmp2; // C + D
if (cc.size() >= 2) ans = max(ans, work(cc, c)); // C + C
if (dd.size() >= 2) ans = max(ans, work(dd, d)); // D + D
cout << ans << endl;
return 0;
}