-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorder.cpp
45 lines (40 loc) · 1.05 KB
/
order.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
int main() {
ifstream fin("milkorder.in");
ofstream fout("milkorder.out");
int n, m, k;
fin >> n >> m >> k;
vector<int> ord(m);
vector<bool> cows(n+1, 0);
vector<pair<int,int>> sp(k);
for (int& i : ord) fin >> i;
for (pair<int,int>& pr : sp) fin >> pr.first >> pr.second;
for (pair<int,int>& pr : sp) {
int target = pr.first;
cows[pr.second] = 1;
for (int i=0; i<ord.size(); i++) {
if (ord[i] == target) {
int oi = i;
int ci = pr.second;
while (ord[oi] != -1 && oi >= 0) {
if (cows[ci] == 0) {
cows[ci] = 1;
ord[oi] = -1;
oi--;
}
ci--;
}
break;
}
}
}
for (int i = 1; i <= n; i++) {
if (!cows[i]) {
fout << i;
break;
}
}
}