Skip to content

Instantly share code, notes, and snippets.

@zsrinivas
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zsrinivas/6387e1a5ce7235fd4ac7 to your computer and use it in GitHub Desktop.
Save zsrinivas/6387e1a5ce7235fd4ac7 to your computer and use it in GitHub Desktop.
spoj → classical → activ → Activities
#include <bits/stdc++.h>
#ifdef __mr__
#include "prettyprint.hpp"
#endif
#define endl ('\n')
using namespace std;
int main() {
ios::sync_with_stdio(0);cin.tie(0);
int n;
while ((cin >> n) && n != -1) {
vector<pair<int32_t, int32_t> > activities(n);
for (auto& x: activities)
cin >> x.first >> x.second;
sort(activities.rbegin(), activities.rend());
vector<int> search = {1000000001}, answer = {1};
for (auto& x: activities) {
answer.push_back((
answer[answer.size() - 1 - (lower_bound(search.rbegin(), search.rend(), x.first) - search.rbegin())] +
answer[answer.size() - 1 - (lower_bound(search.rbegin(), search.rend(), x.second) - search.rbegin())]) % 100000000);
search.push_back(x.first);
}
if (answer[answer.size() - 1] == 0)
cout << "99999999" << endl;
else
cout << setfill('0') << setw(8) << answer[answer.size() - 1] - 1 << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment