Submission #503531

# Submission time Handle Problem Language Result Execution time Memory
503531 2022-01-08T10:15:13 Z andreiE Just Long Neckties (JOI20_ho_t1) C++14
9 / 100
1000 ms 5420 KB
#include <iostream>
#include <algorithm>
using namespace std;

int n, l[200010], maxim = -1, ap_maxim, raspuns[200010];

struct necktie
{
    int l, indice;
} v[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 ++;
        }
    }

    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 ++;

        if (ap_maxim == 0)
        {
            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 ++;
            }
            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 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 4 ms 332 KB Output is correct
24 Correct 5 ms 332 KB Output is correct
25 Correct 7 ms 332 KB Output is correct
26 Correct 7 ms 332 KB Output is correct
27 Correct 6 ms 332 KB Output is correct
28 Correct 7 ms 332 KB Output is correct
29 Correct 4 ms 332 KB Output is correct
30 Correct 4 ms 332 KB Output is correct
31 Correct 5 ms 332 KB Output is correct
32 Correct 5 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 4 ms 332 KB Output is correct
24 Correct 5 ms 332 KB Output is correct
25 Correct 7 ms 332 KB Output is correct
26 Correct 7 ms 332 KB Output is correct
27 Correct 6 ms 332 KB Output is correct
28 Correct 7 ms 332 KB Output is correct
29 Correct 4 ms 332 KB Output is correct
30 Correct 4 ms 332 KB Output is correct
31 Correct 5 ms 332 KB Output is correct
32 Correct 5 ms 332 KB Output is correct
33 Correct 192 ms 4792 KB Output is correct
34 Correct 191 ms 4984 KB Output is correct
35 Correct 204 ms 4804 KB Output is correct
36 Correct 187 ms 5152 KB Output is correct
37 Correct 224 ms 5316 KB Output is correct
38 Correct 195 ms 5420 KB Output is correct
39 Execution timed out 1087 ms 3300 KB Time limit exceeded
40 Halted 0 ms 0 KB -