#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
using namespace std;
// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// END NO SAD
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<ll>> matrix;
typedef pair<ll, ll> pll;
const int KOOSAGA_SZ = 1 << 11;
ll koosagap[2 * KOOSAGA_SZ];
ll koosagas[2 * KOOSAGA_SZ];
ll koosagam[2 * KOOSAGA_SZ];
ll koosagat[2 * KOOSAGA_SZ];
void upd(int idx, ll val) {
idx += KOOSAGA_SZ;
koosagat[idx] = val;
koosagap[idx] = val;
koosagas[idx] = val;
koosagam[idx] = val;
while(idx > 1) {
idx /= 2;
koosagap[idx] = max(koosagap[2*idx], koosagat[2*idx] + koosagap[2*idx+1]);
koosagas[idx] = max(koosagas[2*idx+1], koosagat[2*idx+1] + koosagas[2*idx]);
koosagat[idx] = koosagat[2*idx] + koosagat[2*idx+1];
koosagam[idx] = max(koosagam[2*idx], koosagam[2*idx+1]);
koosagam[idx] = max(koosagam[idx], koosagas[2*idx] + koosagap[2*idx+1]);
}
}
struct state {
int x, y, v, i;
};
bool operator<(state a, state b) {
return pii(a.x, a.y) < pii(b.x, b.y);
}
state l[KOOSAGA_SZ];
int n;
void solve() {
cin >> n;
for(int i = 0; i < n; i++) {
cin >> l[i].x >> l[i].y >> l[i].v;
l[i].i = i;
}
sort(l, l+n);
for(int i = 0; i < n; i++) {
upd(i, l[i].v);
}
ll ret = koosagat[1];
cout << ret << "\n";
}
// are there edge cases (N=1?)
// are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// integer overflow?
// DS reset properly between test cases
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |