-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP1065.cpp
More file actions
66 lines (55 loc) · 1.09 KB
/
P1065.cpp
File metadata and controls
66 lines (55 loc) · 1.09 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<bits/stdc++.h>
using namespace std;
int main()
{
int m, n;
cin >> m >> n;
vector<int> order(m * n, 0);
for (int i = 0; i < n * m; cin >> order[i++]);
vector<vector<int>> machine(n, vector<int>(m));
vector<vector<int>> cost(n, vector<int>(m));
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> machine[i][j];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> cost[i][j];
vector<int> step(n, 0);
vector<int> finish(n, 0);
vector<vector<int>> used(m, vector<int>(10000, 0));
int ans = 0;
for (int idx = 0; idx < m * n; idx++)
{
int job = order[idx] - 1;
int op = step[job];
int mac = machine[job][op] - 1;
int len = cost[job][op];
int t = finish[job] + 1;
while (true)
{
bool ok = true;
for (int k = t; k < t + len; k++)
{
if (used[mac][k])
{
ok = false;
break;
}
}
if (ok)
{
for (int k = t; k < t + len; k++)
{
used[mac][k] = 1;
}
finish[job] = t + len - 1;
ans = max(ans, finish[job]);
step[job]++;
break;
}
t++;
}
}
cout << ans << endl;
return 0;
}