Skip to content

Instantly share code, notes, and snippets.

@cubedtear
Last active December 31, 2016 15:58
Show Gist options
  • Save cubedtear/01741de64398f2103cdd70237dd9f53f to your computer and use it in GitHub Desktop.
Save cubedtear/01741de64398f2103cdd70237dd9f53f to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct sort_pred {
bool operator()(const std::pair<int, int> &left, const std::pair<int, int> &right) {
return left.first == right.first ? left.second < right.second : left.first < right.first;
}
};
int main() {
while (true) {
int cityCount;
cin >> cityCount;
if (cityCount == 0) break;
vector<pair<int, int> > cities;
for (int i = 0; i < cityCount; i++) {
int inv, earn;
cin >> inv >> earn;
cities.push_back(make_pair(inv, earn));
}
sort(cities.begin(), cities.end(), sort_pred());
bool done = false;
for (std::vector<pair<int, int> >::iterator i = cities.begin(); i != cities.end();i++) {
auto next = i;
next++;
if (next != cities.end() && next->first > i->first && next->second <= i->second) {
cout << "NO\n";
done = true;
break;
}
}
if (!done) cout << "SI\n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment