#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;
struct ppl
{
ll x, y, z;
} a[150005];
int N;
map<int, int> mp;
ll ans = -1, bit[150005];
void init()
{
for(int i = 1; i <= N; i++)
bit[i] = -1e10;
}
void modify(int pos, ll val)
{
for(int i = pos; i <= N; i += (i & -i))
bit[i] = max(bit[i], val);
}
ll query(int pos)
{
ll ans = -1e10;
for(int i = pos; i > 0; i -= (i & -i))
ans = max(ans, bit[i]);
return ans;
}
int ypos[150005];
signed main()
{
cin >> N;
for(int i = 1; i <= N; i++)
cin >> a[i].x >> a[i].y >> a[i].z;
sort(a + 1, a + 1 + N, [&](ppl p, ppl q){ return make_tuple(p.x, p.y, p.z) < make_tuple(q.x, q.y, q.z); });
// N = unique(a + 1, a + 1 + N, [&](ppl p, ppl q){ return make_tuple(p.x, p.y, p.z) == make_tuple(q.x, q.y, q.z); }) - a;
int t = 2;
while(t--)
{
vector<int> v;
for(int i = 1; i <= N; i++)
v.emplace_back(a[i].y);
sort(v.begin(), v.end());
for(int i = 1; i <= N; i++)
ypos[i] = lower_bound(v.begin(), v.end(), a[i].y) - v.begin() + 1;
init();
for(int i = 1, nxt = 1; i <= N; i++)
{
while(a[nxt].x < a[i].x)
{
modify(ypos[nxt], a[nxt].z);
nxt++;
}
for(int j = 1; a[j].x < a[i].x; j++)
{
if(a[j].y <= a[i].y)
continue;
ll mxz = query(ypos[j] - 1);
if(mxz > max(a[j].z, a[i].z))
ans = max(ans, a[i].x + a[j].y + mxz);
}
}
for(int i = 1; i <= N; i++)
swap(a[i].y, a[i].z);
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
236 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
260 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
3 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
220 KB |
Output is correct |
19 |
Correct |
2 ms |
224 KB |
Output is correct |
20 |
Correct |
2 ms |
352 KB |
Output is correct |
21 |
Correct |
1 ms |
224 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
236 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
260 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
3 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
220 KB |
Output is correct |
19 |
Correct |
2 ms |
224 KB |
Output is correct |
20 |
Correct |
2 ms |
352 KB |
Output is correct |
21 |
Correct |
1 ms |
224 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
179 ms |
492 KB |
Output is correct |
27 |
Correct |
151 ms |
480 KB |
Output is correct |
28 |
Correct |
113 ms |
488 KB |
Output is correct |
29 |
Correct |
77 ms |
408 KB |
Output is correct |
30 |
Correct |
55 ms |
340 KB |
Output is correct |
31 |
Correct |
150 ms |
476 KB |
Output is correct |
32 |
Correct |
135 ms |
476 KB |
Output is correct |
33 |
Correct |
24 ms |
488 KB |
Output is correct |
34 |
Correct |
27 ms |
400 KB |
Output is correct |
35 |
Correct |
2 ms |
340 KB |
Output is correct |
36 |
Correct |
3 ms |
340 KB |
Output is correct |
37 |
Correct |
17 ms |
508 KB |
Output is correct |
38 |
Correct |
23 ms |
480 KB |
Output is correct |
39 |
Correct |
27 ms |
352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
224 KB |
Output is correct |
2 |
Correct |
1 ms |
224 KB |
Output is correct |
3 |
Correct |
1 ms |
224 KB |
Output is correct |
4 |
Correct |
1 ms |
224 KB |
Output is correct |
5 |
Correct |
0 ms |
224 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Execution timed out |
2058 ms |
6220 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
224 KB |
Output is correct |
2 |
Correct |
1 ms |
224 KB |
Output is correct |
3 |
Correct |
1 ms |
224 KB |
Output is correct |
4 |
Correct |
1 ms |
224 KB |
Output is correct |
5 |
Correct |
0 ms |
224 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Execution timed out |
2058 ms |
6220 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
224 KB |
Output is correct |
2 |
Correct |
1 ms |
224 KB |
Output is correct |
3 |
Correct |
1 ms |
224 KB |
Output is correct |
4 |
Correct |
1 ms |
224 KB |
Output is correct |
5 |
Correct |
0 ms |
224 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Execution timed out |
2058 ms |
6220 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
224 KB |
Output is correct |
2 |
Correct |
1 ms |
224 KB |
Output is correct |
3 |
Correct |
1 ms |
224 KB |
Output is correct |
4 |
Correct |
1 ms |
224 KB |
Output is correct |
5 |
Correct |
0 ms |
224 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Execution timed out |
2058 ms |
6220 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
236 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
260 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
3 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
220 KB |
Output is correct |
19 |
Correct |
2 ms |
224 KB |
Output is correct |
20 |
Correct |
2 ms |
352 KB |
Output is correct |
21 |
Correct |
1 ms |
224 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
179 ms |
492 KB |
Output is correct |
27 |
Correct |
151 ms |
480 KB |
Output is correct |
28 |
Correct |
113 ms |
488 KB |
Output is correct |
29 |
Correct |
77 ms |
408 KB |
Output is correct |
30 |
Correct |
55 ms |
340 KB |
Output is correct |
31 |
Correct |
150 ms |
476 KB |
Output is correct |
32 |
Correct |
135 ms |
476 KB |
Output is correct |
33 |
Correct |
24 ms |
488 KB |
Output is correct |
34 |
Correct |
27 ms |
400 KB |
Output is correct |
35 |
Correct |
2 ms |
340 KB |
Output is correct |
36 |
Correct |
3 ms |
340 KB |
Output is correct |
37 |
Correct |
17 ms |
508 KB |
Output is correct |
38 |
Correct |
23 ms |
480 KB |
Output is correct |
39 |
Correct |
27 ms |
352 KB |
Output is correct |
40 |
Correct |
1 ms |
224 KB |
Output is correct |
41 |
Correct |
1 ms |
224 KB |
Output is correct |
42 |
Correct |
1 ms |
224 KB |
Output is correct |
43 |
Correct |
1 ms |
224 KB |
Output is correct |
44 |
Correct |
0 ms |
224 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Execution timed out |
2058 ms |
6220 KB |
Time limit exceeded |
51 |
Halted |
0 ms |
0 KB |
- |