Pagini recente » Cod sursa (job #2277387) | Cod sursa (job #3335635) | Cod sursa (job #882383) | Cod sursa (job #1721035) | Cod sursa (job #3345884)
#include <algorithm>
#include <iostream>
#include <fstream>
#include <climits>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
// #include <bits/std++.h>
#define in fin
#define out fout
#define int long long
using namespace std;
ifstream fin("pachete.in");
ofstream fout("pachete.out");
struct punct{
int x, y;
};
bool cmp_universal(punct &a, punct &b){
if(a.x != b.x) return a.x < b.x;
else return a.y < b.y;
}
int nr_de_subsecvente(vector<int> &v){
if(v.empty()) return 0;
if(v[0] <= 0){
// e invers
for(int i = 0; i < v.size(); i++) v[i] = -v[i];
}
vector<int> capete;
capete.push_back(v[0]);
for(int i = 1; i < v.size(); i++){
if(v[i] < capete[0]){
capete.insert(capete.begin(), v[i]);
}else{
int it = upper_bound(capete.begin(), capete.end(), v[i]) - capete.begin() - 1;
capete[it] = v[i];
}
}
return capete.size(); // nu e tocmai optim dar sa zicem
}
signed main(){
ios_base::sync_with_stdio(false);
in.tie(NULL);
// de ce is totimpul asa tractor astea
int n; in >> n;
int xs, ys; in >> xs >> ys;
vector<punct> cdr[4];
for(int i = 0; i < n; i++){
int x, y; in >> x >> y;
x -= xs;
x -= ys; // translating
if(x < 0 && y > 0) cdr[0].push_back({-x, y});
if(x > 0 && y > 0) cdr[1].push_back({x, y});
if(x < 0 && y < 0) cdr[2].push_back({-x, -y});
if(x > 0 && y < 0) cdr[3].push_back({x, -y});
}
sort(cdr[0].begin(), cdr[0].end(), cmp_universal);
sort(cdr[1].begin(), cdr[1].end(), cmp_universal);
sort(cdr[2].begin(), cdr[2].end(), cmp_universal);
sort(cdr[3].begin(), cdr[3].end(), cmp_universal);
// sort dupa x bine si trb sa vad cate pot face cresc cu y
vector<int> minimude[4];
for(int i = 0; i < 4; i++){
for(int j = 0; j < cdr[i].size(); j++){
minimude[i].push_back(cdr[i][j].y);
}
}
int total = 0;
for(int i = 0; i < 4; i++){
total += nr_de_subsecvente(minimude[i]);
// cout << "i = " << i << " nr = " << nr_de_subsecvente(minimude[i]) << '\n';
// cout << "i = " << i << " v = ";
// for(const punct &x : cdr[i]) cout << "( " << x.x << " " << x.y << " ) ";
// cout << '\n';
}
out << total << '\n';
return 0;
}