Skip to content

Instantly share code, notes, and snippets.

@yusuke024
Last active August 29, 2015 14:24
Show Gist options
  • Save yusuke024/39e2cade5490eb053b9d to your computer and use it in GitHub Desktop.
Save yusuke024/39e2cade5490eb053b9d to your computer and use it in GitHub Desktop.
// https://arena.topcoder.com/#/u/practiceCode/10882/7034/7850/1/265822
#include <map>
#include <vector>
using namespace std;
struct BestHotel {
int numberOfDisadvantageous(vector<int> price, vector<int> quality) {
map<int, int> bestHotels;
int n = price.size();
int t = 0, p, q, bq, tq;
for (int i = 0; i < n; ++i) {
p = price[i];
q = quality[i];
bq = 0;
tq = 0;
for (auto &pair: bestHotels) {
if (pair.first < p) {
bq = pair.second >= bq ? pair.second : bq;
}
if (pair.first == p) {
tq = pair.second;
}
if (pair.first > p && pair.second < q + 1) {
pair.second = q + 1;
++t;
}
}
if (q > bq && q >= tq) {
bestHotels[p] = q;
} else {
++t;
}
}
return t;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment