# Snowboots 2018 Gold C++ Debugging

## Problem Info

USACO Gold Snowboots. I’m getting the first three testcases

## My Code

Here’s my code:

#include <iostream>
#include <fstream>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
#define STDN 100002

//ofstream fout("snowboots.out");
//ifstream fin("snowboots.in");

// CLASSES
class Tile { // tiles
public:
int id;
int d;
};
class Boot { // boots
public:
int id;
int d, s;
int ans;

bool operator<(const Boot& a) const {
return a.d > d;
}
};

// STRUCTS
struct tCmp_id {
bool operator()(Tile a, Tile b) const {
return a.id < b.id;
}
};
struct tCmp_d {
bool operator()(Tile a, Tile b) const {
return a.d < b.d;
}
};

// VARIABLES
int N, M; // N = num tiles, M = num boots
bool RET[STDN];
Boot B[STDN];
set<Tile, tCmp_d> T; // tiles compared by depth
set<Tile, tCmp_id> TQ; // tiles compared by id; TQ stores all tiles of less than a certain depth at some time
multiset<int> D; // stores distances between tiles

// CLASSES

int main(){
// get data
cin >> N >> M;
for(int i = 1; i <= N; i++){
Tile t;
t.id = i;
cin >> t.d;
if(i == 1 || i == N){
TQ.insert(t);
} else {
T.insert(t);
}
}
for(int i = 1; i <= M; i++){
B[i].id = i;
cin >> B[i].d >> B[i].s;
}

sort(B + 1, B + M);

D.insert(N - 1);

//
for(int i = 1; i <= M; i++){
while(!T.empty() && (*T.begin()).d <= B[i].d){
auto ct = *T.begin(); // current tile
auto pt = *(--TQ.upper_bound(ct)); // prev tile
auto nt = *TQ.upper_bound(ct); // next tile

// current tile goes from set T to set TQ
T.erase(T.begin());
TQ.insert(ct);

D.erase(D.lower_bound(nt.id - pt.id));
D.insert(nt.id - ct.id);
D.insert(ct.id - pt.id);
}

B[B[i].id].ans = (*D.rbegin() <= B[i].s);
}

for(int i = 1; i <= M; i++) {
cout << B[i].ans << endl;
}
}


## What I’ve Tried

I’ve tried to change the ints to longs, and using some USACO test cases, but they seem to be a bit too large for testing.

Does anyone know what’s wrong here, or can lend a hint as to what is going on? Thanks in advance