Cod sursa(job #1900333)

Utilizator Andrei1998Andrei Constantinescu Andrei1998 Data 3 martie 2017 12:13:10
Problema NextSeq Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <fstream>
#include <algorithm>

using namespace std;

int P, N, M;

const int NMAX = 10000 + 5;
int x[NMAX];
int a[NMAX];
int b[NMAX];

bool ls() {
    if (N < M)
        return true;

    for (int i = N; i; -- i)
        if (a[i] < b[i])
            return 1;
        else if (a[i] > b[i])
            return 0;
    return 0;
}

void add() {
    for (int i = 1; i <= N + 1; ++ i) {
        if (a[i] < P) {
            if (i == N + 1)
                ++ N;
            ++ a[i];
            while (-- i)
                a[i] = 1;
            break;
        }
    }
}

int main()
{
    ifstream cin("nextseq.in");
    ofstream cout("nextseq.out");

    cin >> P >> N >> M;

    for (int i = 1; i <= P; ++ i)
        cin >> x[i];
    sort(x + 1, x + P + 1);

    for (int i = N; i; -- i) {
        cin >> a[i];
        a[i] = lower_bound(x + 1, x + P + 1, a[i]) - x;
    }
    for (int i = M; i; -- i) {
        cin >> b[i];
        b[i] = lower_bound(x + 1, x + P + 1, b[i]) - x;
    }

    int cnt = -1;
    while (ls())
        add(), ++ cnt;
    cout << cnt << '\n';
    return 0;
}