I recently switched from Java to C++ and am still getting used to it. Im currently coding the Gold problem A Pie for A Pie and I am having an error with getting multiset’s upper_bound to work:
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;
class Rating {
public:
int b;
int e;
};
class Pie {
public:
int id;
Rating r;
};
struct bessieCmp {
bool operator() (Pie a, Pie b) const{
return (a.r.b > b.r.b);
}
};
struct elsieCmp {
bool operator() (Pie a, Pie b) const{
return (a.r.e > b.r.e);
}
};
const int NUM = 100001;
int N, D;
int BFS[2][NUM]; // 0 is bessie, 1 is elsie
bool V[2][NUM];
Pie B[NUM], E[NUM]; // all of bessie/elsie's pies
multiset<Pie, bessieCmp> BC; // bessie and elsie's current pies
multiset<Pie, elsieCmp> EC;
vector<int> R; // root node ids(all bessie pies that have elsie rating 0)
void bessieBFS(int id, int d) {
if(V[0][id]) return;
V[0][id] = true;
auto ptr = BC.upper_bound(BC, BC + NUM - 1, d-1);
}
void elsieBFS(int id, int d){
if(V[1][id]) return;
V[1][id] = true;
}
int main(){
fill(BFS, BFS + 100000, 100002);
// get data
cin >> N >> D;
for(int i = 1; i <= N; i++){
B[i].id = i;
cin >> B[i].r.b >> B[i].r.e;
BC.insert(B[i]);
if(B[i].r.e == 0) {
BFS[0][i] = 0;
R.push_back(i);
}else {
BC.insert(B[i]);
}
}
for(int i = 1; i <= N; i++){
E[i].id = N + i;
cin >> E[i].r.b >> E[i].r.e;
EC.insert(E[i]);
}
// run bfs
for(int i = 0, n = R.size(); i < n; i++){
bessieBFS(R[i], 0);
}
}
specifically, I’m getting red squiggles under the line that says
auto ptr = BC.upper_bound(BC, BC + NUM - 1, d-1);
Specifically under the ‘upper bound’, and I’m not quite sure what’s wrong here. I tried searching online and viewing the official solution’s code but Im stuck on what I’m doing wrong. Any help appreciated!