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;
}

#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;
}

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

Stop Buying Cheap Alternatives This Portable Blender Bottle Is the Real Deal

📢 As an Amazon Associate, I earn from qualifying purchases.There comes a point when you realise that tolerating a frustrating situation is costing you...

Famed mountaineer Nirmal Purja, 43, among 10 climbers killed after avalanche in Pakistan

Tragedy in the Karakoram: Nirmal Purja Among 10 Lost in Avalanche In a devastating turn of events for the global mountaineering community, renowned high-altitude climber...

How Under Desk Storage Is Quietly Changing the Game

📢 As an Amazon Associate, I earn from qualifying purchases.There comes a point when you realise that tolerating a frustrating situation is costing you...

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!