-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathd.cpp
43 lines (40 loc) · 769 Bytes
/
d.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
#include <bits/stdc++.h>
using namespace std;
int calcWaitTime(vector<int> &priority, int position)
{
int in = -1;
int maxi = -1;
int n = priority.size();
for (int i = 0; i < n; i++)
{
if (maxi < priority[i])
{
in = i;
maxi = priority[i];
}
}
if (in == position)
return 0;
priority[in] = -1;
for (int i = 0; i < in; i++)
{
if (priority[i] > 0)
priority[i]++;
}
return 1 + calcWaitTime(priority, position);
}
int main()
{
int t, n;
cin >> n;
vector<int> array(n);
for (int i = 0; i < n; i++)
{
cin >> array[i];
}
int k;
cin >> k;
k--;
cout << 1 + calcWaitTime(array, k) << endl;
return 0;
}