Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <stdio.h>
- #include <cstdlib>
- #include <vector>
- #include <fstream>
- #include <tuple>
- #include <functional>
- #ifdef EVAL
- #define getc getc_unlocked
- #endif
- using namespace std;
- ofstream fout("output.txt");
- //lista di adiacenza. vediamo se è faster
- FILE *fr;
- int c, sol;
- int getInt(){
- sol = 0;
- while((c = getc(fr)) > 32)
- sol = (sol<<3) + (sol<<1) + c - 48;
- return sol;
- }
- int main(){
- fr = fopen("input.txt", "r");
- int a, M = getInt(), F = getInt(), C = getInt();
- vector<int> G[M];
- for(int i = 0; i < C; i++){
- a = getInt() - 1;
- G[a].push_back(getInt());
- }
- vector<int> LIS;
- for(vector<int> &m : G){
- sort(m.begin(), m.end(), greater<int>());
- for(int f : m){
- auto ub = upper_bound(LIS.begin(), LIS.end(), f);
- if(ub != m.begin() && *prev(ub) == f) //se non è strettamente minore
- continue;
- else if(ub == LIS.end())
- LIS.push_back(f);
- else
- *ub = f;
- }
- }
- fout << LIS.size() * 2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement