Pagini recente » Cod sursa (job #1674680) | Cod sursa (job #2305862) | Cod sursa (job #1427363) | Cod sursa (job #2338789) | Cod sursa (job #1777933)
#include <fstream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
ifstream fin("nextseq.in");
ofstream fout("nextseq.out");
int main() {
int valsCount, aCount, bCount;
fin >> valsCount >> aCount >> bCount;
vector<int> vals(valsCount);
for (auto& it : vals)
fin >> it;
sort(vals.begin(), vals.end());
vector<int> a(bCount), b(bCount);
for (int i = 0; i < bCount; ++i) {
if (i < bCount - aCount)
a[i] = 0;
else {
fin >> a[i];
a[i] = lower_bound(vals.begin(), vals.end(), a[i]) - vals.begin() + 1;
}
}
for (int i = 0; i < bCount; ++i) {
fin >> b[i];
b[i] = lower_bound(vals.begin(), vals.end(), b[i]) - vals.begin() + 1;
}
vector<int> pow(bCount);
pow[0] = 1;
for (int i = 1; i < bCount; ++i)
pow[i] = min(100, pow[i - 1] * valsCount);
int start = 0;
while (start < bCount && a[start] == b[start])
++start;
if (start == bCount) {
fout << 0 << '\n';
return 0;
}
int ans = (b[start] - a[start] - 1) * pow[bCount - start - 1];
for (int curr = start + 1; curr < bCount; ++curr) {
ans += (valsCount - a[curr]) * pow[bCount - curr - 1];
ans += (b[curr] - 1) * pow[bCount - curr - 1];
}
fout << ans << '\n';
return 0;
}
//Trust me, I'm the Doctor!