-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFountains.cpp
More file actions
79 lines (78 loc) · 1.91 KB
/
Fountains.cpp
File metadata and controls
79 lines (78 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll,ll>
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define FastRead ios_base::sync_with_stdio(false);cin.tie(NULL);
int main()
{
FastRead
vector < pii > v1,v2;
int n,c,d;
cin >> n >> c >> d;
int bb,pp;
char cc;
while(n--)
{
cin >> bb >> pp >> cc;
if(cc == 'C')
{
if(pp<=c)
v1.push_back(pii(pp,bb));
}
else if(cc == 'D')
{
if(pp<=d)
v2.push_back(pii(pp,bb));
}
}
ll ans = 0, mx;
sort(all(v1));
sort(all(v2));
if(v1.size() && v2.size())
{
for(int i=0;i<v1.size();i++)
ans = max(ans,v1[i].second);
mx = 0;
for(int i=0;i<v2.size();i++)
mx = max(mx,v2[i].second);
ans += mx;
}
if(v1.size() > 1)
{
mx = v1[0].second;
int pos = 0;
for(int i=1;i<v1.size();i++)
{
mx = max(mx,v1[i].second);
while(pos+1 < i && v1[i].F+v1[pos+1].F <= c)
pos++;
while(pos >= 0 && v1[i].F+v1[pos].F > c)
pos--;
if(pos<0)
break;
ans = max(ans,v1[i].S+v1[pos].S);
v1[i].S = mx;
}
}
if(v2.size() > 1)
{
mx = v2[0].second;
int pos = 0;
for(int i=1;i<v2.size();i++)
{
mx = max(mx,v2[i].second);
while(pos+1 < i && v2[i].F+v2[pos+1].F <= d)
pos++;
while(pos >= 0 && v2[i].F+v2[pos].F > d)
pos--;
if(pos<0)
break;
ans = max(ans,v2[i].S+v2[pos].S);
v2[i].S = mx;
}
}
cout << ans << endl;
}