Cod sursa(job #2924229)

Utilizator andreiiorgulescuandrei iorgulescu andreiiorgulescu Data 27 septembrie 2022 17:08:38
Problema Subsir crescator maximal Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.06 kb
#include <bits/stdc++.h>

using namespace std;

int t,n,d[1005];
int v[1005];
pair<int,int>a[1005];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> t;
    for (int q = 1; q <= t; q++)
    {
        for (int i = 1; i <= 1000; i++)
            d[i] = 1e9;
        cin >> n;
        for (int i = 1; i <= n; i++)
            cin >> a[i].first;
        for (int i = 1; i <= n; i++)
            cin >> a[i].second;
        sort(a + 1,a + n + 1);
        for (int i = 1; i <= n; i++)
            v[i] = a[i].second;
        for (int i = 1; i <= n; i++)
        {
            int st = 0,pas = 1 << 9;
            while (pas != 0)
            {
                if (st + pas <= n and d[st + pas] < v[i])
                    st += pas;
                pas /= 2;
            }
            st++;
            d[st] = v[i];
        }
        int ans = 0;
        for (int i = 1; i <= n; i++)
            if (d[i] != 1e9)
                ans = i;
        cout << ans << '\n';
    }
    return 0;
}