93 lines
2.6 KiB
C++
93 lines
2.6 KiB
C++
#include <iostream>
|
|
using namespace std;
|
|
int main()
|
|
{
|
|
int n, anxu[101] = { 0 }, dui[101] = { 0 }, fid[101] = { 0 };
|
|
bool pan = 0;
|
|
|
|
cin >> n >> anxu[0] >> dui[0];
|
|
for (int i = 1; i <= anxu[0]; i++) {
|
|
cin >> anxu[i];
|
|
fid[anxu[i]] = i;
|
|
if (anxu[i] == 1) {
|
|
pan = 1;
|
|
}
|
|
}
|
|
for (int i = 1; i <= dui[0]; i++) {
|
|
int car, id;
|
|
cin >> car >> id;
|
|
dui[id] = car;
|
|
if (car == 1) {
|
|
cout << id;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
if (pan == 0) {
|
|
int tou = 1, wei = 1, last = 1;
|
|
for (int i = 1; i <= n; i++) {
|
|
if (dui[i] > 0) {
|
|
if (fid[dui[i]] > 0) {
|
|
wei = fid[dui[i]] - 1;
|
|
for (int j = i - 1; j >= last; j--) {
|
|
if (tou > wei) {
|
|
break;
|
|
} else {
|
|
if (dui[j] == 0) {
|
|
dui[j] = anxu[wei];
|
|
wei--;
|
|
}
|
|
}
|
|
}
|
|
tou = fid[dui[i]] + 1;
|
|
last = i+1;
|
|
}
|
|
}
|
|
}
|
|
|
|
// wei = anxu[0];
|
|
// for (int j = n; j >= last; j--) {
|
|
// if (tou > wei) {
|
|
// break;
|
|
// } else {
|
|
// if (dui[j] == 0) {
|
|
// dui[j] = anxu[wei];
|
|
// wei--;
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
for (int i = 1; i <= n; i++) {
|
|
if (dui[i] == 0) {
|
|
cout << i;
|
|
return 0;
|
|
}
|
|
}
|
|
}else{
|
|
int tou = 1, wei = 1, last = 1;
|
|
for (int i = 1; i <= n; i++) {
|
|
if (dui[i] > 0) {
|
|
if (fid[dui[i]] > 0) {
|
|
wei = fid[dui[i]] - 1;
|
|
for (int j = last; j <=i-1; j--) {
|
|
if (tou > wei) {
|
|
break;
|
|
} else {
|
|
if (dui[j] == 0) {
|
|
dui[j] = anxu[tou];
|
|
if(anxu[tou]==1){
|
|
cout<<j;
|
|
return 0;
|
|
}
|
|
tou++;
|
|
}
|
|
}
|
|
}
|
|
tou = fid[dui[i]] + 1;
|
|
last = i+1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|