Submission #866919

# Submission time Handle Problem Language Result Execution time Memory
866919 2023-10-27T10:49:14 Z boris_mihov Team Contest (JOI22_team) C++17
100 / 100
83 ms 7868 KB
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>

typedef long long llong;
const int MAXN = 150000 + 10;

struct Student
{
    int x, y, z;
};

int n;
int a[MAXN];
int b[MAXN];
int c[MAXN];
Student s[MAXN];

void solve()
{
    std::iota(a + 1, a + 1 + n, 1);
    std::iota(b + 1, b + 1 + n, 1);
    std::iota(c + 1, c + 1 + n, 1);
    std::sort(a + 1, a + 1 + n, [&](int i, int j)
    {
        return s[i].x < s[j].x;
    });

    std::sort(b + 1, b + 1 + n, [&](int i, int j)
    {
        return s[i].y < s[j].y;
    });

    std::sort(c + 1, c + 1 + n, [&](int i, int j)
    {
        return s[i].z < s[j].z;
    });

    int ptrA = n;
    int ptrB = n;
    int ptrC = n;

    while (ptrA > 0 && ptrB > 0 && ptrC > 0)
    {
        if (s[a[ptrA]].x <= s[b[ptrB]].x)
        {
            ptrB--;
            continue;
        }

        if (s[a[ptrA]].x <= s[c[ptrC]].x)
        {
            ptrC--;
            continue;
        }

        if (s[b[ptrB]].y <= s[a[ptrA]].y)
        {
            ptrA--;
            continue;
        }

        if (s[b[ptrB]].y <= s[c[ptrC]].y)
        {
            ptrC--;
            continue;
        }

        if (s[c[ptrC]].z <= s[a[ptrA]].z)
        {
            ptrA--;
            continue;
        }

        if (s[c[ptrC]].z <= s[b[ptrB]].z)
        {
            ptrB--;
            continue;
        }

        std::cout << s[a[ptrA]].x + s[b[ptrB]].y + s[c[ptrC]].z << '\n';
        return;
    }

    std::cout << -1 << '\n';
}

void input()
{
    std::cin >> n;
    for (int i = 1 ; i <= n ; ++i)
    {
        std::cin >> s[i].x >> s[i].y >> s[i].z;
    }
}

void fastIOI()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}

int main()
{
    fastIOI();
    input();
    solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2388 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2508 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2404 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2512 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2388 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2508 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2404 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2512 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 2 ms 2652 KB Output is correct
27 Correct 2 ms 2520 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 2 ms 2652 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 2 ms 2488 KB Output is correct
33 Correct 2 ms 2652 KB Output is correct
34 Correct 2 ms 2904 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2392 KB Output is correct
37 Correct 2 ms 2652 KB Output is correct
38 Correct 2 ms 2456 KB Output is correct
39 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2512 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 33 ms 4724 KB Output is correct
12 Correct 21 ms 3928 KB Output is correct
13 Correct 23 ms 4176 KB Output is correct
14 Correct 34 ms 4700 KB Output is correct
15 Correct 27 ms 4688 KB Output is correct
16 Correct 24 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2512 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 33 ms 4724 KB Output is correct
12 Correct 21 ms 3928 KB Output is correct
13 Correct 23 ms 4176 KB Output is correct
14 Correct 34 ms 4700 KB Output is correct
15 Correct 27 ms 4688 KB Output is correct
16 Correct 24 ms 4700 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2524 KB Output is correct
22 Correct 37 ms 5104 KB Output is correct
23 Correct 33 ms 4712 KB Output is correct
24 Correct 27 ms 4188 KB Output is correct
25 Correct 38 ms 4960 KB Output is correct
26 Correct 28 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2512 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 33 ms 4724 KB Output is correct
12 Correct 21 ms 3928 KB Output is correct
13 Correct 23 ms 4176 KB Output is correct
14 Correct 34 ms 4700 KB Output is correct
15 Correct 27 ms 4688 KB Output is correct
16 Correct 24 ms 4700 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2524 KB Output is correct
22 Correct 37 ms 5104 KB Output is correct
23 Correct 33 ms 4712 KB Output is correct
24 Correct 27 ms 4188 KB Output is correct
25 Correct 38 ms 4960 KB Output is correct
26 Correct 28 ms 4956 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 1 ms 2392 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 1 ms 2520 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 44 ms 5212 KB Output is correct
35 Correct 48 ms 5204 KB Output is correct
36 Correct 47 ms 5464 KB Output is correct
37 Correct 48 ms 5608 KB Output is correct
38 Correct 33 ms 5488 KB Output is correct
39 Correct 19 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2512 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 33 ms 4724 KB Output is correct
12 Correct 21 ms 3928 KB Output is correct
13 Correct 23 ms 4176 KB Output is correct
14 Correct 34 ms 4700 KB Output is correct
15 Correct 27 ms 4688 KB Output is correct
16 Correct 24 ms 4700 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2524 KB Output is correct
22 Correct 37 ms 5104 KB Output is correct
23 Correct 33 ms 4712 KB Output is correct
24 Correct 27 ms 4188 KB Output is correct
25 Correct 38 ms 4960 KB Output is correct
26 Correct 28 ms 4956 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 1 ms 2392 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 1 ms 2520 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 44 ms 5212 KB Output is correct
35 Correct 48 ms 5204 KB Output is correct
36 Correct 47 ms 5464 KB Output is correct
37 Correct 48 ms 5608 KB Output is correct
38 Correct 33 ms 5488 KB Output is correct
39 Correct 19 ms 4188 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 2 ms 2396 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 2 ms 2652 KB Output is correct
44 Correct 56 ms 5972 KB Output is correct
45 Correct 59 ms 5972 KB Output is correct
46 Correct 57 ms 5968 KB Output is correct
47 Correct 61 ms 6100 KB Output is correct
48 Correct 38 ms 5972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2388 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2508 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2404 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2512 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 2 ms 2652 KB Output is correct
27 Correct 2 ms 2520 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 2 ms 2652 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 2 ms 2488 KB Output is correct
33 Correct 2 ms 2652 KB Output is correct
34 Correct 2 ms 2904 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2392 KB Output is correct
37 Correct 2 ms 2652 KB Output is correct
38 Correct 2 ms 2456 KB Output is correct
39 Correct 1 ms 2392 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 0 ms 2396 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 1 ms 2392 KB Output is correct
44 Correct 1 ms 2392 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 0 ms 2512 KB Output is correct
47 Correct 0 ms 2396 KB Output is correct
48 Correct 0 ms 2396 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 33 ms 4724 KB Output is correct
51 Correct 21 ms 3928 KB Output is correct
52 Correct 23 ms 4176 KB Output is correct
53 Correct 34 ms 4700 KB Output is correct
54 Correct 27 ms 4688 KB Output is correct
55 Correct 24 ms 4700 KB Output is correct
56 Correct 1 ms 2392 KB Output is correct
57 Correct 1 ms 2396 KB Output is correct
58 Correct 0 ms 2396 KB Output is correct
59 Correct 1 ms 2396 KB Output is correct
60 Correct 1 ms 2524 KB Output is correct
61 Correct 37 ms 5104 KB Output is correct
62 Correct 33 ms 4712 KB Output is correct
63 Correct 27 ms 4188 KB Output is correct
64 Correct 38 ms 4960 KB Output is correct
65 Correct 28 ms 4956 KB Output is correct
66 Correct 1 ms 2392 KB Output is correct
67 Correct 1 ms 2396 KB Output is correct
68 Correct 1 ms 2392 KB Output is correct
69 Correct 1 ms 2392 KB Output is correct
70 Correct 2 ms 2652 KB Output is correct
71 Correct 1 ms 2520 KB Output is correct
72 Correct 1 ms 2396 KB Output is correct
73 Correct 44 ms 5212 KB Output is correct
74 Correct 48 ms 5204 KB Output is correct
75 Correct 47 ms 5464 KB Output is correct
76 Correct 48 ms 5608 KB Output is correct
77 Correct 33 ms 5488 KB Output is correct
78 Correct 19 ms 4188 KB Output is correct
79 Correct 1 ms 2396 KB Output is correct
80 Correct 2 ms 2396 KB Output is correct
81 Correct 1 ms 2652 KB Output is correct
82 Correct 2 ms 2652 KB Output is correct
83 Correct 56 ms 5972 KB Output is correct
84 Correct 59 ms 5972 KB Output is correct
85 Correct 57 ms 5968 KB Output is correct
86 Correct 61 ms 6100 KB Output is correct
87 Correct 38 ms 5972 KB Output is correct
88 Correct 83 ms 7868 KB Output is correct
89 Correct 74 ms 7760 KB Output is correct
90 Correct 75 ms 7656 KB Output is correct
91 Correct 75 ms 7836 KB Output is correct
92 Correct 66 ms 6492 KB Output is correct
93 Correct 75 ms 6688 KB Output is correct
94 Correct 70 ms 6816 KB Output is correct
95 Correct 48 ms 7508 KB Output is correct
96 Correct 72 ms 7640 KB Output is correct
97 Correct 38 ms 7784 KB Output is correct
98 Correct 34 ms 6480 KB Output is correct
99 Correct 64 ms 6496 KB Output is correct