Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2), problem: (C) Fountains Solution In C/C++

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int n, c, d;
int bit[2][100100];

void insertBIT (int id, int a, int x) {
for (int i=a; i<=100100; i+=i&(-i))
bit[id][i]=max(x, bit[id][i]);
}

int queryBIT (int id, int a) {
int res=0;
for (int i=a; i>0; i-=i&(-i))
res=max(res, bit[id][i]);
return res;
}
int main (int argc, char ** argv) {
cin>>n>>c>>d;
int b, p, ans=0, cmax=0, dmax=0;
char id;
for (int i=0; i<n; i++) {
cin>>b>>p>>id;
int res=0;
if (id==’C’) {
if (p<=c) {
cmax=max(b, cmax);
res=queryBIT(0, c-p);
if (res)
ans=max(ans, res+b);
insertBIT(0, p, b);
}
}
else {
if (p<=d) {
dmax=max(b, dmax);
res=queryBIT(1, d-p);
if (res)
ans=max(ans, res+b);
insertBIT(1, p, b);
}
}
}
if (dmax && cmax)
ans=max(ans, cmax+dmax);
cout<<ans<<‘\n’;
return 0;
}

(Visited 21 times, 1 visits today)

About the Author:

Leave A Comment