#include "fish.h"
#include "bits/stdc++.h";
using namespace std;
#define forR(i, x) for(int i = 0; i < (x); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
struct pii{int a, b;};
ll INF = 1e16;
ll rSum(int i, vector<pii>& wx, vll& psa) {
int ind = upper_bound(all(wx), i, [](int a, pii b){return a < b.a;}) - wx.begin();
if(ind - 1 == -1) return 0;
return psa[ind-1];
}
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
vector<vector<pii>> wx(N);
forR(i, M) wx[X[i]].push_back({Y[i], W[i]});
forR(i, N) sort(all(wx[i]), [](pii a, pii b){return a.a < b.a;});
vvll wpsa(N);
forR(i, N) if(!wx[i].empty()) {
wpsa[i].push_back(wx[i][0].b);
REP(j, 1, wx[i].size()) wpsa[i].push_back(wx[i][j].b + wpsa[i].back());
}
vector<set<int>> sCare(N);
forR(i, M) {
if(X[i] > 0) sCare[X[i]-1].insert(Y[i] + 1);
if(X[i] + 1 < N) sCare[X[i] + 1].insert(Y[i] + 1);
if(X[i] + 2 < N) sCare[X[i] + 2].insert(Y[i] + 1);
sCare[X[i]].insert(Y[i]+1);
}
forR(i, N) sCare[i].insert(0);
vector<vi> care(N);
forR(i, N) for(int j : sCare[i]) care[i].push_back(j);
vvll I(N), D(N), E(N);
forR(i, N) I[i].resize(care[i].size()), D[i].resize(care[i].size()), E[i].resize(care[i].size());
// h = HEIGHT, not the index of last element!
forR(i, N) {
ll besIE = -INF, besII = -INF;
if(i > 0) {
forR(ki, care[i-1].size()) {
int k = care[i-1][ki];
besIE = max(besIE, E[i-1][ki] - rSum(k-1, wx[i-1], wpsa[i-1]));
}
}
int api = 0;
forR(hi, care[i].size()) {
int h = care[i][hi];
if(h > 0) {
if(i == 0) I[i][hi] = 0;
else {
I[i][hi] = max(I[i][hi], besIE + rSum(h-1, wx[i-1], wpsa[i-1]));
while(api < care[i-1].size() && care[i-1][api] <= h) {
int k = care[i-1][api];
besII = max(besII, I[i-1][api] - rSum(k-1, wx[i-1], wpsa[i-1]));
++api;
}
I[i][hi] = max(I[i][hi], besII + rSum(h-1, wx[i-1], wpsa[i-1]));
}
}
}
api = (int) care[i-1].size() - 1;
ll besD = -INF;
for(int hi = (int) care[i].size() - 1; hi >= 0; --hi){
int h = care[i][hi];
if(h > 0) {
if(i == 0) D[i][hi] = 0;
else {
while(api >= 0 && care[i-1][api] >= h + 1) {
int k = care[i-1][api];
besD = max(besD, max(I[i-1][api], D[i-1][api]) + rSum(k-1, wx[i], wpsa[i]));
--api;
}
D[i][hi] = max(D[i][hi], besD - rSum(h-1, wx[i], wpsa[i]));
}
}
}
ll besE = -INF;
if(i > 0) {
forR(yi, care[i-1].size()) besE = max(besE, E[i-1][yi]);
}
forR(hi, care[i].size()){
int h = care[i][hi];
if(i == 0) E[i][hi] = 0;
else {
int pInd = lower_bound(all(care[i-1]), h) - care[i-1].begin();
if(care[i-1][pInd] == h) {
ll tot = max(I[i-1][pInd], D[i-1][pInd]) + rSum(h-1, wx[i], wpsa[i]);
E[i][hi] = max(E[i][hi], max(tot, besE));
}
}
}
}
ll mx = 0;
forR(hi, care[N-1].size()) if(care[N-1][hi] > 0) mx = max(mx, max(I[N-1][hi], D[N-1][hi]));
forR(hi, care[N-1].size()) mx = max(mx, E[N-1][hi]);
return mx;
}
Compilation message
fish.cpp:2:29: warning: extra tokens at end of #include directive
2 | #include "bits/stdc++.h";
| ^
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:5:45: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pii>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
5 | #define REP(i, a, b) for(int i = (a); i < (b); ++i)
| ^
fish.cpp:30:9: note: in expansion of macro 'REP'
30 | REP(j, 1, wx[i].size()) wpsa[i].push_back(wx[i][j].b + wpsa[i].back());
| ^~~
fish.cpp:4:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
| ^
fish.cpp:49:11: note: in expansion of macro 'forR'
49 | forR(ki, care[i-1].size()) {
| ^~~~
fish.cpp:4:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
| ^
fish.cpp:55:9: note: in expansion of macro 'forR'
55 | forR(hi, care[i].size()) {
| ^~~~
fish.cpp:61:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | while(api < care[i-1].size() && care[i-1][api] <= h) {
| ~~~~^~~~~~~~~~~~~~~~~~
fish.cpp:4:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
| ^
fish.cpp:90:11: note: in expansion of macro 'forR'
90 | forR(yi, care[i-1].size()) besE = max(besE, E[i-1][yi]);
| ^~~~
fish.cpp:4:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
| ^
fish.cpp:92:9: note: in expansion of macro 'forR'
92 | forR(hi, care[i].size()){
| ^~~~
fish.cpp:4:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
| ^
fish.cpp:105:7: note: in expansion of macro 'forR'
105 | forR(hi, care[N-1].size()) if(care[N-1][hi] > 0) mx = max(mx, max(I[N-1][hi], D[N-1][hi]));
| ^~~~
fish.cpp:4:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
| ^
fish.cpp:106:7: note: in expansion of macro 'forR'
106 | forR(hi, care[N-1].size()) mx = max(mx, E[N-1][hi]);
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
118 ms |
53828 KB |
Output is correct |
2 |
Correct |
144 ms |
62536 KB |
Output is correct |
3 |
Correct |
26 ms |
36440 KB |
Output is correct |
4 |
Correct |
31 ms |
36440 KB |
Output is correct |
5 |
Correct |
737 ms |
137440 KB |
Output is correct |
6 |
Correct |
478 ms |
137640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
225 ms |
64956 KB |
Output is correct |
3 |
Correct |
268 ms |
73920 KB |
Output is correct |
4 |
Correct |
115 ms |
53836 KB |
Output is correct |
5 |
Correct |
140 ms |
62512 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
26 ms |
36248 KB |
Output is correct |
11 |
Correct |
26 ms |
36444 KB |
Output is correct |
12 |
Correct |
161 ms |
60044 KB |
Output is correct |
13 |
Correct |
193 ms |
70156 KB |
Output is correct |
14 |
Correct |
136 ms |
57052 KB |
Output is correct |
15 |
Correct |
139 ms |
54216 KB |
Output is correct |
16 |
Correct |
133 ms |
57088 KB |
Output is correct |
17 |
Correct |
156 ms |
63312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
36444 KB |
Output is correct |
2 |
Correct |
27 ms |
36440 KB |
Output is correct |
3 |
Correct |
49 ms |
40284 KB |
Output is correct |
4 |
Correct |
43 ms |
41540 KB |
Output is correct |
5 |
Correct |
73 ms |
49740 KB |
Output is correct |
6 |
Correct |
70 ms |
49744 KB |
Output is correct |
7 |
Correct |
69 ms |
49492 KB |
Output is correct |
8 |
Correct |
72 ms |
49492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
33 ms |
7312 KB |
Output is correct |
18 |
Correct |
40 ms |
6916 KB |
Output is correct |
19 |
Correct |
27 ms |
7128 KB |
Output is correct |
20 |
Correct |
31 ms |
6292 KB |
Output is correct |
21 |
Correct |
24 ms |
6236 KB |
Output is correct |
22 |
Correct |
55 ms |
12000 KB |
Output is correct |
23 |
Correct |
10 ms |
3160 KB |
Output is correct |
24 |
Correct |
28 ms |
7240 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
8 ms |
2808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
33 ms |
7312 KB |
Output is correct |
18 |
Correct |
40 ms |
6916 KB |
Output is correct |
19 |
Correct |
27 ms |
7128 KB |
Output is correct |
20 |
Correct |
31 ms |
6292 KB |
Output is correct |
21 |
Correct |
24 ms |
6236 KB |
Output is correct |
22 |
Correct |
55 ms |
12000 KB |
Output is correct |
23 |
Correct |
10 ms |
3160 KB |
Output is correct |
24 |
Correct |
28 ms |
7240 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
8 ms |
2808 KB |
Output is correct |
27 |
Correct |
3 ms |
2396 KB |
Output is correct |
28 |
Correct |
225 ms |
32188 KB |
Output is correct |
29 |
Correct |
427 ms |
57424 KB |
Output is correct |
30 |
Correct |
696 ms |
98136 KB |
Output is correct |
31 |
Correct |
673 ms |
96888 KB |
Output is correct |
32 |
Correct |
269 ms |
39544 KB |
Output is correct |
33 |
Correct |
664 ms |
100732 KB |
Output is correct |
34 |
Correct |
682 ms |
100920 KB |
Output is correct |
35 |
Correct |
123 ms |
28888 KB |
Output is correct |
36 |
Correct |
601 ms |
82788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
36444 KB |
Output is correct |
2 |
Correct |
27 ms |
36440 KB |
Output is correct |
3 |
Correct |
49 ms |
40284 KB |
Output is correct |
4 |
Correct |
43 ms |
41540 KB |
Output is correct |
5 |
Correct |
73 ms |
49740 KB |
Output is correct |
6 |
Correct |
70 ms |
49744 KB |
Output is correct |
7 |
Correct |
69 ms |
49492 KB |
Output is correct |
8 |
Correct |
72 ms |
49492 KB |
Output is correct |
9 |
Correct |
121 ms |
69972 KB |
Output is correct |
10 |
Correct |
52 ms |
28496 KB |
Output is correct |
11 |
Correct |
133 ms |
56704 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
26 ms |
36444 KB |
Output is correct |
19 |
Correct |
26 ms |
36396 KB |
Output is correct |
20 |
Correct |
26 ms |
36180 KB |
Output is correct |
21 |
Correct |
26 ms |
36444 KB |
Output is correct |
22 |
Correct |
153 ms |
68432 KB |
Output is correct |
23 |
Correct |
182 ms |
76884 KB |
Output is correct |
24 |
Correct |
228 ms |
80468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
118 ms |
53828 KB |
Output is correct |
2 |
Correct |
144 ms |
62536 KB |
Output is correct |
3 |
Correct |
26 ms |
36440 KB |
Output is correct |
4 |
Correct |
31 ms |
36440 KB |
Output is correct |
5 |
Correct |
737 ms |
137440 KB |
Output is correct |
6 |
Correct |
478 ms |
137640 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
225 ms |
64956 KB |
Output is correct |
9 |
Correct |
268 ms |
73920 KB |
Output is correct |
10 |
Correct |
115 ms |
53836 KB |
Output is correct |
11 |
Correct |
140 ms |
62512 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
26 ms |
36248 KB |
Output is correct |
17 |
Correct |
26 ms |
36444 KB |
Output is correct |
18 |
Correct |
161 ms |
60044 KB |
Output is correct |
19 |
Correct |
193 ms |
70156 KB |
Output is correct |
20 |
Correct |
136 ms |
57052 KB |
Output is correct |
21 |
Correct |
139 ms |
54216 KB |
Output is correct |
22 |
Correct |
133 ms |
57088 KB |
Output is correct |
23 |
Correct |
156 ms |
63312 KB |
Output is correct |
24 |
Correct |
25 ms |
36444 KB |
Output is correct |
25 |
Correct |
27 ms |
36440 KB |
Output is correct |
26 |
Correct |
49 ms |
40284 KB |
Output is correct |
27 |
Correct |
43 ms |
41540 KB |
Output is correct |
28 |
Correct |
73 ms |
49740 KB |
Output is correct |
29 |
Correct |
70 ms |
49744 KB |
Output is correct |
30 |
Correct |
69 ms |
49492 KB |
Output is correct |
31 |
Correct |
72 ms |
49492 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
604 KB |
Output is correct |
42 |
Correct |
0 ms |
604 KB |
Output is correct |
43 |
Correct |
1 ms |
604 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
1 ms |
604 KB |
Output is correct |
46 |
Correct |
1 ms |
604 KB |
Output is correct |
47 |
Correct |
1 ms |
604 KB |
Output is correct |
48 |
Correct |
33 ms |
7312 KB |
Output is correct |
49 |
Correct |
40 ms |
6916 KB |
Output is correct |
50 |
Correct |
27 ms |
7128 KB |
Output is correct |
51 |
Correct |
31 ms |
6292 KB |
Output is correct |
52 |
Correct |
24 ms |
6236 KB |
Output is correct |
53 |
Correct |
55 ms |
12000 KB |
Output is correct |
54 |
Correct |
10 ms |
3160 KB |
Output is correct |
55 |
Correct |
28 ms |
7240 KB |
Output is correct |
56 |
Correct |
1 ms |
604 KB |
Output is correct |
57 |
Correct |
8 ms |
2808 KB |
Output is correct |
58 |
Correct |
3 ms |
2396 KB |
Output is correct |
59 |
Correct |
225 ms |
32188 KB |
Output is correct |
60 |
Correct |
427 ms |
57424 KB |
Output is correct |
61 |
Correct |
696 ms |
98136 KB |
Output is correct |
62 |
Correct |
673 ms |
96888 KB |
Output is correct |
63 |
Correct |
269 ms |
39544 KB |
Output is correct |
64 |
Correct |
664 ms |
100732 KB |
Output is correct |
65 |
Correct |
682 ms |
100920 KB |
Output is correct |
66 |
Correct |
123 ms |
28888 KB |
Output is correct |
67 |
Correct |
601 ms |
82788 KB |
Output is correct |
68 |
Correct |
121 ms |
69972 KB |
Output is correct |
69 |
Correct |
52 ms |
28496 KB |
Output is correct |
70 |
Correct |
133 ms |
56704 KB |
Output is correct |
71 |
Correct |
1 ms |
344 KB |
Output is correct |
72 |
Correct |
0 ms |
344 KB |
Output is correct |
73 |
Correct |
0 ms |
348 KB |
Output is correct |
74 |
Correct |
0 ms |
348 KB |
Output is correct |
75 |
Correct |
0 ms |
348 KB |
Output is correct |
76 |
Correct |
0 ms |
348 KB |
Output is correct |
77 |
Correct |
26 ms |
36444 KB |
Output is correct |
78 |
Correct |
26 ms |
36396 KB |
Output is correct |
79 |
Correct |
26 ms |
36180 KB |
Output is correct |
80 |
Correct |
26 ms |
36444 KB |
Output is correct |
81 |
Correct |
153 ms |
68432 KB |
Output is correct |
82 |
Correct |
182 ms |
76884 KB |
Output is correct |
83 |
Correct |
228 ms |
80468 KB |
Output is correct |
84 |
Correct |
782 ms |
119620 KB |
Output is correct |
85 |
Correct |
794 ms |
127172 KB |
Output is correct |
86 |
Correct |
533 ms |
140676 KB |
Output is correct |
87 |
Correct |
537 ms |
145116 KB |
Output is correct |
88 |
Correct |
0 ms |
348 KB |
Output is correct |
89 |
Correct |
525 ms |
145096 KB |
Output is correct |
90 |
Correct |
406 ms |
112976 KB |
Output is correct |
91 |
Correct |
246 ms |
85588 KB |
Output is correct |