Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- int m;
- cin >> m;
- set<pair<int, int> > maski_plus, mask_minus, zenski_plus, zenski_minus;
- for(int i = 0; i < m; i++) {
- int x; cin >> x;
- char c; cin >> c;
- if(c == '+') {
- maski_plus.insert(make_pair(x, i));
- }
- else {
- mask_minus.insert(make_pair(x, i));
- }
- }
- for(int i = 0; i < m; i++) {
- int x; cin >> x;
- char c; cin >> c;
- if(c == '+') {
- zenski_plus.insert(make_pair(x, i));
- }
- else {
- zenski_minus.insert(make_pair(x, i));
- }
- }
- int pairs = 0;
- for(pair<int, int> p : maski_plus) {
- set<pair<int, int> >::iterator it = zenski_minus.lower_bound(make_pair(p.first + 1, 0));
- if(it != zenski_minus.end()) {
- pairs++;
- zenski_minus.erase(it);
- }
- }
- for(pair<int, int> p : zenski_plus) {
- set<pair<int, int> >::iterator it = mask_minus.lower_bound(make_pair(p.first + 1, 0));
- if(it != mask_minus.end()) {
- pairs++;
- mask_minus.erase(it);
- }
- }
- cout << pairs << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement