#include <bits/stdc++.h>
#include "fish.h"
using namespace std;
#define ll long long
#define ff first
#define ss second
int n; //global var for storing N
vector<pair<int, int> > fishes[100005]; //Stores the fishes in each row
struct SegmentTree{
ll tree[1 << 18];
void init(){
memset(tree, 0xcf, sizeof(tree));
}
void upd(int idx, int s, int e, int l, int r, ll val){
if(e < l || r < s) return;
if(l <= s && e <= r){
tree[idx] = max(tree[idx], val);
return;
}
int mid = (s + e) / 2;
upd(2 * idx, s, mid, l, r, val);
upd(2 * idx + 1, mid + 1, e, l, r, val);
}
ll qry(int idx, int s, int e, int x){
if(s == e) return tree[idx];
int mid = (s + e) / 2;
if(x <= mid) return qry(2 * idx, s, mid, x);
return qry(2 * idx + 1, mid + 1, e, x);
}
}st_up, st_down;
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W){
n = N;
for(int i = 0; i < M; i++) fishes[X[i] + 1].push_back({Y[i] + 1, W[i]});
ll till_now = 0;
st_down.init();
for(int i = 1; i <= n; i++){
sort(fishes[i].begin(), fishes[i].end());
for(auto [j, w] : fishes[i]) st_up.upd(1, 0, n + 1, j + 1, n + 1, st_up.qry(1, 0, n + 1, j) + w);
reverse(fishes[i].begin(), fishes[i].end());
for(auto [j, w] : fishes[i]) st_down.upd(1, 0, n + 1, 0, j - 1, st_down.qry(1, 0, n + 1, j) + w);
ll u_res = st_up.qry(1, 0, n + 1, n + 1), d_res = st_down.qry(1, 0, n + 1, 0);
st_up.upd(1, 0, n + 1, 0, n + 1, d_res);
st_down.upd(1, 0, n + 1, 0, n + 1, till_now);
till_now = max(u_res, d_res);
}
return st_down.qry(1, 0, n + 1, 0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
47 ms |
10960 KB |
1st lines differ - on the 1st token, expected: '40313272768926', found: '-3472328296003917948' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
6748 KB |
1st lines differ - on the 1st token, expected: '2', found: '-3472328296227680304' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
6748 KB |
1st lines differ - on the 1st token, expected: '10082010', found: '-3472328296217598295' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
6748 KB |
1st lines differ - on the 1st token, expected: '3', found: '-3472328296227680304' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
6748 KB |
1st lines differ - on the 1st token, expected: '3', found: '-3472328296227680304' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
6748 KB |
1st lines differ - on the 1st token, expected: '3', found: '-3472328296227680304' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
6748 KB |
1st lines differ - on the 1st token, expected: '10082010', found: '-3472328296217598295' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
47 ms |
10960 KB |
1st lines differ - on the 1st token, expected: '40313272768926', found: '-3472328296003917948' |
2 |
Halted |
0 ms |
0 KB |
- |