#include <iostream>
#include <algorithm>
using namespace std;
int n, l[200010], maxim = -1, ap_maxim, raspuns[200010];
struct necktie
{
int l, indice;
} v[200010];
struct max_in_
{
int maxim;
int ap;
} maxim_in_dreapta[200010], maxim_in_stanga[200010];
bool criteriu (necktie a, necktie b)
{
return a.l <= b.l;
}
int main()
{
cin >> n;
for (int i = 1; i <= n + 1; i++)
{
cin >> v[i].l;
v[i].indice = i;
}
for (int i = 1; i <= n; i++)
cin >> l[i];
sort (l + 1, l + n + 1);
sort (v + 1, v + n + 2, criteriu);
for (int i = 1; i <= n; i++)
{
if (max (v[i + 1].l - l[i], 0) > maxim)
{
maxim = max (v[i + 1].l - l[i], 0);
ap_maxim = 1;
}
else if (max (v[i + 1].l - l[i], 0) == maxim)
{
ap_maxim ++;
}
}
for (int i = n; i >= 1; i--)
{
maxim_in_dreapta[i].maxim = maxim_in_dreapta[i + 1].maxim;
maxim_in_dreapta[i].ap = maxim_in_dreapta [i + 1].ap;
if (maxim_in_dreapta[i].maxim < max(v[i + 1].l - l[i], 0))
{
maxim_in_dreapta[i].maxim = max(v[i + 1].l - l[i], 0);
maxim_in_dreapta[i].ap = 1;
}
else if (maxim_in_dreapta[i].maxim == max(v[i + 1].l - l[i], 0))
{
maxim_in_dreapta[i].ap ++;
}
}
raspuns[v[1].indice] = maxim;
for (int i = 2; i <= n + 1; i++)
{
if (max(v[i].l - l[i - 1], 0) == maxim)
{
ap_maxim --;
}
if (max (v[i - 1].l - l[i - 1], 0) > maxim)
{
maxim = max (v[i - 1].l - l[i - 1], 0);
ap_maxim = 1;
}
else if (max (v[i - 1].l - l[i - 1], 0) == maxim)
ap_maxim ++;
maxim_in_stanga [i - 1].maxim = maxim_in_stanga[i - 2].maxim;
maxim_in_stanga[i - 1].ap = maxim_in_stanga[i - 2].ap;
if (maxim_in_stanga[i - 1].maxim < max (v[i - 1].l - l[i - 1], 0))
{
maxim_in_stanga[i - 1].maxim = max (v[i - 1].l - l[i - 1], 0);
maxim_in_stanga[i - 1].ap = 1;
}
else if (maxim_in_stanga[i - 1].maxim == max (v[i - 1].l - l[i - 1], 0))
maxim_in_stanga[i - 1].ap ++;
if (ap_maxim == 0)
{
//cout << "abecedar" << ' ' << i << ' ';
maxim = -1;
/**for (int j = 1; j < i; j++)
{
if (max(v[j].l - l[j], 0) > maxim)
{
maxim = max(v[j].l - l[j], 0);
ap_maxim = 1;
}
else if (max(v[j].l - l[j], 0) == maxim)
ap_maxim ++;
}*/
maxim = maxim_in_stanga[i - 1].maxim;
ap_maxim = maxim_in_stanga[i - 1].ap;
//cout << maxim << ' ' << ap_maxim << '\n';
if (i != n + 1 && maxim_in_dreapta[i].maxim > maxim)
{
maxim = maxim_in_dreapta[i].maxim;
ap_maxim = maxim_in_dreapta[i].ap;
}
/**for (int j = i; j <= n; j++)
{
if (max(v[j + 1].l - l[j], 0) > maxim)
{
maxim = max(v[j + 1].l - l[j], 0);
ap_maxim = 1;
}
else if (max(v[j + 1].l - l[j], 0) == maxim)
ap_maxim ++;
}*/
}
raspuns[v[i].indice] = maxim;
}
for (int i = 1; i <= n + 1; i++)
cout << raspuns[i] << ' ';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
316 KB |
Output is correct |
18 |
Correct |
2 ms |
312 KB |
Output is correct |
19 |
Correct |
2 ms |
292 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
3 ms |
312 KB |
Output is correct |
23 |
Correct |
3 ms |
352 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
360 KB |
Output is correct |
27 |
Correct |
2 ms |
312 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
2 ms |
312 KB |
Output is correct |
32 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
316 KB |
Output is correct |
18 |
Correct |
2 ms |
312 KB |
Output is correct |
19 |
Correct |
2 ms |
292 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
3 ms |
312 KB |
Output is correct |
23 |
Correct |
3 ms |
352 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
360 KB |
Output is correct |
27 |
Correct |
2 ms |
312 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
2 ms |
312 KB |
Output is correct |
32 |
Correct |
2 ms |
332 KB |
Output is correct |
33 |
Correct |
196 ms |
8088 KB |
Output is correct |
34 |
Correct |
192 ms |
8460 KB |
Output is correct |
35 |
Correct |
196 ms |
8116 KB |
Output is correct |
36 |
Correct |
197 ms |
8624 KB |
Output is correct |
37 |
Correct |
212 ms |
8844 KB |
Output is correct |
38 |
Correct |
223 ms |
8868 KB |
Output is correct |
39 |
Correct |
188 ms |
7928 KB |
Output is correct |
40 |
Correct |
190 ms |
7812 KB |
Output is correct |
41 |
Correct |
194 ms |
7876 KB |
Output is correct |
42 |
Correct |
188 ms |
7904 KB |
Output is correct |
43 |
Correct |
197 ms |
7816 KB |
Output is correct |
44 |
Correct |
183 ms |
7636 KB |
Output is correct |
45 |
Correct |
197 ms |
7536 KB |
Output is correct |
46 |
Correct |
182 ms |
7476 KB |
Output is correct |
47 |
Execution timed out |
1031 ms |
3772 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |