#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;
int n, m;
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
n = N;
m = M;
vector<map<int, lli>> grid(n);
frange(i, m) {
grid[X[i]][Y[i]+1] = W[i];
}
frange(i, n) grid[i][0] = grid[i][2e9] = 0;
vector<map<int, lli>> dp1(n), dp2(n);
for(auto p : grid[0]) {
dp2[0][p.f] = p.s;
auto it = dp2[0].find(p.f);
if(it != dp2[0].begin())
dp2[0][p.f] += (*prev(it)).s;
}
forr(i, 1, n) {
lli ma = 0;
for(auto p : dp1[i-1]) ma = max(ma, p.s);
deque<lli> dq;
lli tot = 0;
for(auto p : grid[i]) {
tot += p.s;
auto it = dp2[i-1].lower_bound(p.f);
lli v2 = 2e9+1;
auto it2 = grid[i].upper_bound(p.f);
if(it2 != grid[i].end()) v2 = (*it2).f;
while(it != dp2[i-1].end() && (*it).f < v2) {
lli v = (*it).s - tot;
while(dq.size() && dq.back() <= v) dq.pop_back();
dq.pb(v);
it++;
}
if(dq.size())
dp2[i][p.s] = dq.front() + tot;
dp2[i][p.s] = max(dp2[i][p.s], ma + tot);
}
tot = 0;
dq = {};
auto it = grid[i].end();
while(it != grid[i].begin()) {
it--;
auto p= *it;
dp1[i][p.f] = 0;
auto it2 = dp2[i-1].upper_bound(p.f);
if(it2 != dp2[i-1].begin()) {
it2--;
dp1[i][p.f] = (*it2).s;
}
if(dq.size()) {
dp1[i][p.f] = max(dp1[i][p.f], dq.front() + tot);
}
it2 = dp1[i-1].lower_bound(p.f);
lli v2 = 2e9+1;
auto it3 = grid[i].upper_bound(p.f);
if(it3 != grid[i].end()) v2 = (*it3).f;
while(it2 != dp1[i-1].end() && (*it2).f < v2) {
lli v = (*it2).s - tot;
while(dq.size() && dq.back() <= v) dq.pop_back();
dq.pb(v);
it2++;
}
tot += p.s;
}
}
lli ma = 0;
for(auto p : dp1[n-1]) ma = max(ma, p.s);
return ma;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
113 ms |
53072 KB |
Output is correct |
2 |
Correct |
142 ms |
60496 KB |
Output is correct |
3 |
Correct |
44 ms |
45656 KB |
Output is correct |
4 |
Correct |
45 ms |
45724 KB |
Output is correct |
5 |
Correct |
628 ms |
108992 KB |
Output is correct |
6 |
Correct |
300 ms |
93564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
284 ms |
70224 KB |
Output is correct |
3 |
Correct |
356 ms |
81748 KB |
Output is correct |
4 |
Correct |
111 ms |
53272 KB |
Output is correct |
5 |
Correct |
134 ms |
60500 KB |
Output is correct |
6 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '4044', found: '2022' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
45652 KB |
Output is correct |
2 |
Correct |
47 ms |
45652 KB |
Output is correct |
3 |
Incorrect |
71 ms |
53332 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '26722445760742' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '4044', found: '2022' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '4044', found: '2022' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '4044', found: '2022' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
45652 KB |
Output is correct |
2 |
Correct |
47 ms |
45652 KB |
Output is correct |
3 |
Incorrect |
71 ms |
53332 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '26722445760742' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
113 ms |
53072 KB |
Output is correct |
2 |
Correct |
142 ms |
60496 KB |
Output is correct |
3 |
Correct |
44 ms |
45656 KB |
Output is correct |
4 |
Correct |
45 ms |
45724 KB |
Output is correct |
5 |
Correct |
628 ms |
108992 KB |
Output is correct |
6 |
Correct |
300 ms |
93564 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
284 ms |
70224 KB |
Output is correct |
9 |
Correct |
356 ms |
81748 KB |
Output is correct |
10 |
Correct |
111 ms |
53272 KB |
Output is correct |
11 |
Correct |
134 ms |
60500 KB |
Output is correct |
12 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '4044', found: '2022' |
13 |
Halted |
0 ms |
0 KB |
- |