#include <bits/stdc++.h>
#include "fish.h"
using namespace std;
struct RYBA
{
int y,c;
long long wynik=0,wynik2=0;
long long l=0,s=0,p=0;
long long suma=0;
RYBA(int yy=0, int cc=0)
{
y=yy;
c=cc;
wynik=0;wynik2=0;
l=0;s=0,p=0;
suma=0;
}
bool operator <(const RYBA &B)const
{
return y<B.y;
}
};
vector<RYBA>V[100009];
long long max_weights(int N, int M, vector<int>X, vector<int>Y, vector<int>W)
{
for(int i=0;i<M;i++)
{
V[X[i]+1].push_back(RYBA(Y[i]+1,W[i]));
//cout<<"x="<<X[i]+1<<" y="<<Y[i]+1<<" w="<<W[i]<<endl;
}
for(int i=1;i<=N;i++)
{
V[i].push_back(RYBA(N+1,0));
V[i].push_back(RYBA(0,0));
sort(V[i].begin(),V[i].end());
}
for(int i=1;i<=N;i++)
{
int Hl=0,Hp=0;
long long l=0,p=0,s=0;
for(int j=0;j<V[i].size();j++)
{
while(Hl<V[i-1].size()&&V[i-1][Hl].y<=V[i][j].y-1)
{
l+=V[i-1][Hl].c;
Hl++;
}
while(Hp<V[i+1].size()&&V[i+1][Hp].y<=V[i][j].y-1)
{
p+=V[i+1][Hp].c;
Hp++;
}
V[i][j].l=l;
V[i][j].s=s;
V[i][j].p=p;
V[i][j].suma=l+p;
//cout<<" x="<<i-1<<" y="<<V[i][j].y-1<<" c="<<V[i][j].c<<" l="<<l<<" s="<<s<<" p="<<p<<endl;
s+=V[i][j].c;
}
}
for(int i=0;i<V[1].size();i++)
{
V[1][i].wynik=V[1][i].suma;
V[1][i].wynik2=V[1][i].suma;
}
long long WYNIK=0;
for(int i=2;i<=N;i++)
{
int h;
long long maxx;
if(i>=2)
{
h=0;maxx=0;
for(int j=0;j<V[i].size();j++)
{
while(h<V[i-2].size()&&V[i-2][h].y<=V[i][j].y)
{
maxx=max(maxx,V[i-2][h].wynik-V[i-2][h].p);
h++;
}
V[i][j].wynik=max(V[i][j].wynik,maxx+V[i][j].suma);
}
h=V[i-2].size()-1;maxx=0;
for(int j=V[i].size()-1;j>=0;j--)
{
while(h>=0&&V[i][j].y<=V[i-2][h].y)
{
maxx=max(maxx,V[i-2][h].wynik);
h--;
}
V[i][j].wynik=max(V[i][j].wynik,maxx+V[i][j].p);
V[i][j].wynik2=V[i][j].wynik;
}
}
h=0;maxx=0;
for(int j=0;j<V[i].size();j++)
{
while(h<V[i-1].size()&&V[i-1][h].y<=V[i][j].y)
{
maxx=max(maxx,V[i-1][h].wynik2-V[i-1][h].p-V[i-1][h].s);
h++;
}
V[i][j].wynik=max(V[i][j].wynik,maxx+V[i][j].suma);
V[i][j].wynik2=max(V[i][j].wynik2,maxx+V[i][j].suma);
}
h=V[i-1].size()-1;maxx=0;
for(int j=V[i].size()-1;j>=0;j--)
{
while(h>=0&&V[i][j].y<=V[i-1][h].y)
{
maxx=max(maxx,V[i-1][h].wynik);
h--;
}
V[i][j].wynik=max(V[i][j].wynik,maxx-V[i][j].s+V[i][j].p);
WYNIK=max(WYNIK,V[i][j].wynik);
}
}
return WYNIK;
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:41:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<RYBA>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int j=0;j<V[i].size();j++)
| ~^~~~~~~~~~~~
fish.cpp:43:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<RYBA>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | while(Hl<V[i-1].size()&&V[i-1][Hl].y<=V[i][j].y-1)
| ~~^~~~~~~~~~~~~~
fish.cpp:48:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<RYBA>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | while(Hp<V[i+1].size()&&V[i+1][Hp].y<=V[i][j].y-1)
| ~~^~~~~~~~~~~~~~
fish.cpp:61:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<RYBA>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for(int i=0;i<V[1].size();i++)
| ~^~~~~~~~~~~~
fish.cpp:74:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<RYBA>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for(int j=0;j<V[i].size();j++)
| ~^~~~~~~~~~~~
fish.cpp:76:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<RYBA>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | while(h<V[i-2].size()&&V[i-2][h].y<=V[i][j].y)
| ~^~~~~~~~~~~~~~
fish.cpp:96:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<RYBA>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
96 | for(int j=0;j<V[i].size();j++)
| ~^~~~~~~~~~~~
fish.cpp:98:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<RYBA>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
98 | while(h<V[i-1].size()&&V[i-1][h].y<=V[i][j].y)
| ~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
21636 KB |
Output is correct |
2 |
Correct |
67 ms |
24636 KB |
Output is correct |
3 |
Correct |
19 ms |
15056 KB |
Output is correct |
4 |
Correct |
19 ms |
15068 KB |
Output is correct |
5 |
Correct |
164 ms |
45060 KB |
Output is correct |
6 |
Correct |
211 ms |
53388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
91 ms |
29332 KB |
Output is correct |
3 |
Correct |
114 ms |
34248 KB |
Output is correct |
4 |
Correct |
60 ms |
21736 KB |
Output is correct |
5 |
Correct |
67 ms |
24656 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
2 ms |
2652 KB |
Output is correct |
10 |
Correct |
18 ms |
15060 KB |
Output is correct |
11 |
Correct |
21 ms |
15072 KB |
Output is correct |
12 |
Correct |
57 ms |
21612 KB |
Output is correct |
13 |
Correct |
79 ms |
24700 KB |
Output is correct |
14 |
Correct |
54 ms |
21620 KB |
Output is correct |
15 |
Correct |
60 ms |
23772 KB |
Output is correct |
16 |
Correct |
53 ms |
21736 KB |
Output is correct |
17 |
Correct |
59 ms |
23772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
15164 KB |
Output is correct |
2 |
Correct |
24 ms |
15064 KB |
Output is correct |
3 |
Correct |
53 ms |
22344 KB |
Output is correct |
4 |
Correct |
38 ms |
20864 KB |
Output is correct |
5 |
Correct |
79 ms |
31464 KB |
Output is correct |
6 |
Correct |
71 ms |
30820 KB |
Output is correct |
7 |
Correct |
75 ms |
31488 KB |
Output is correct |
8 |
Correct |
84 ms |
31500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2772 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
3 ms |
2644 KB |
Output is correct |
10 |
Correct |
3 ms |
3028 KB |
Output is correct |
11 |
Correct |
2 ms |
2796 KB |
Output is correct |
12 |
Correct |
3 ms |
2792 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
2 ms |
2772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2772 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
3 ms |
2644 KB |
Output is correct |
10 |
Correct |
3 ms |
3028 KB |
Output is correct |
11 |
Correct |
2 ms |
2796 KB |
Output is correct |
12 |
Correct |
3 ms |
2792 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
2 ms |
2772 KB |
Output is correct |
15 |
Correct |
2 ms |
2656 KB |
Output is correct |
16 |
Correct |
3 ms |
2900 KB |
Output is correct |
17 |
Correct |
22 ms |
7400 KB |
Output is correct |
18 |
Correct |
24 ms |
8664 KB |
Output is correct |
19 |
Correct |
22 ms |
8928 KB |
Output is correct |
20 |
Correct |
24 ms |
8808 KB |
Output is correct |
21 |
Correct |
22 ms |
8804 KB |
Output is correct |
22 |
Correct |
39 ms |
14412 KB |
Output is correct |
23 |
Correct |
6 ms |
3796 KB |
Output is correct |
24 |
Correct |
14 ms |
6228 KB |
Output is correct |
25 |
Correct |
2 ms |
2772 KB |
Output is correct |
26 |
Correct |
6 ms |
3820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2772 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
3 ms |
2644 KB |
Output is correct |
10 |
Correct |
3 ms |
3028 KB |
Output is correct |
11 |
Correct |
2 ms |
2796 KB |
Output is correct |
12 |
Correct |
3 ms |
2792 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
2 ms |
2772 KB |
Output is correct |
15 |
Correct |
2 ms |
2656 KB |
Output is correct |
16 |
Correct |
3 ms |
2900 KB |
Output is correct |
17 |
Correct |
22 ms |
7400 KB |
Output is correct |
18 |
Correct |
24 ms |
8664 KB |
Output is correct |
19 |
Correct |
22 ms |
8928 KB |
Output is correct |
20 |
Correct |
24 ms |
8808 KB |
Output is correct |
21 |
Correct |
22 ms |
8804 KB |
Output is correct |
22 |
Correct |
39 ms |
14412 KB |
Output is correct |
23 |
Correct |
6 ms |
3796 KB |
Output is correct |
24 |
Correct |
14 ms |
6228 KB |
Output is correct |
25 |
Correct |
2 ms |
2772 KB |
Output is correct |
26 |
Correct |
6 ms |
3820 KB |
Output is correct |
27 |
Correct |
4 ms |
3516 KB |
Output is correct |
28 |
Correct |
99 ms |
30116 KB |
Output is correct |
29 |
Correct |
129 ms |
39228 KB |
Output is correct |
30 |
Correct |
134 ms |
38404 KB |
Output is correct |
31 |
Correct |
149 ms |
38468 KB |
Output is correct |
32 |
Correct |
126 ms |
41756 KB |
Output is correct |
33 |
Correct |
140 ms |
38412 KB |
Output is correct |
34 |
Correct |
147 ms |
38472 KB |
Output is correct |
35 |
Correct |
67 ms |
18252 KB |
Output is correct |
36 |
Correct |
148 ms |
41476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
15164 KB |
Output is correct |
2 |
Correct |
24 ms |
15064 KB |
Output is correct |
3 |
Correct |
53 ms |
22344 KB |
Output is correct |
4 |
Correct |
38 ms |
20864 KB |
Output is correct |
5 |
Correct |
79 ms |
31464 KB |
Output is correct |
6 |
Correct |
71 ms |
30820 KB |
Output is correct |
7 |
Correct |
75 ms |
31488 KB |
Output is correct |
8 |
Correct |
84 ms |
31500 KB |
Output is correct |
9 |
Correct |
80 ms |
31160 KB |
Output is correct |
10 |
Correct |
60 ms |
19716 KB |
Output is correct |
11 |
Correct |
133 ms |
36852 KB |
Output is correct |
12 |
Correct |
2 ms |
2652 KB |
Output is correct |
13 |
Correct |
2 ms |
2652 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2644 KB |
Output is correct |
17 |
Correct |
2 ms |
2644 KB |
Output is correct |
18 |
Correct |
21 ms |
15188 KB |
Output is correct |
19 |
Correct |
21 ms |
15084 KB |
Output is correct |
20 |
Correct |
19 ms |
15060 KB |
Output is correct |
21 |
Correct |
19 ms |
15176 KB |
Output is correct |
22 |
Correct |
96 ms |
27932 KB |
Output is correct |
23 |
Correct |
135 ms |
36868 KB |
Output is correct |
24 |
Correct |
162 ms |
37448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
21636 KB |
Output is correct |
2 |
Correct |
67 ms |
24636 KB |
Output is correct |
3 |
Correct |
19 ms |
15056 KB |
Output is correct |
4 |
Correct |
19 ms |
15068 KB |
Output is correct |
5 |
Correct |
164 ms |
45060 KB |
Output is correct |
6 |
Correct |
211 ms |
53388 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
91 ms |
29332 KB |
Output is correct |
9 |
Correct |
114 ms |
34248 KB |
Output is correct |
10 |
Correct |
60 ms |
21736 KB |
Output is correct |
11 |
Correct |
67 ms |
24656 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2652 KB |
Output is correct |
16 |
Correct |
18 ms |
15060 KB |
Output is correct |
17 |
Correct |
21 ms |
15072 KB |
Output is correct |
18 |
Correct |
57 ms |
21612 KB |
Output is correct |
19 |
Correct |
79 ms |
24700 KB |
Output is correct |
20 |
Correct |
54 ms |
21620 KB |
Output is correct |
21 |
Correct |
60 ms |
23772 KB |
Output is correct |
22 |
Correct |
53 ms |
21736 KB |
Output is correct |
23 |
Correct |
59 ms |
23772 KB |
Output is correct |
24 |
Correct |
21 ms |
15164 KB |
Output is correct |
25 |
Correct |
24 ms |
15064 KB |
Output is correct |
26 |
Correct |
53 ms |
22344 KB |
Output is correct |
27 |
Correct |
38 ms |
20864 KB |
Output is correct |
28 |
Correct |
79 ms |
31464 KB |
Output is correct |
29 |
Correct |
71 ms |
30820 KB |
Output is correct |
30 |
Correct |
75 ms |
31488 KB |
Output is correct |
31 |
Correct |
84 ms |
31500 KB |
Output is correct |
32 |
Correct |
2 ms |
2644 KB |
Output is correct |
33 |
Correct |
2 ms |
2644 KB |
Output is correct |
34 |
Correct |
2 ms |
2644 KB |
Output is correct |
35 |
Correct |
2 ms |
2644 KB |
Output is correct |
36 |
Correct |
2 ms |
2644 KB |
Output is correct |
37 |
Correct |
2 ms |
2772 KB |
Output is correct |
38 |
Correct |
2 ms |
2644 KB |
Output is correct |
39 |
Correct |
2 ms |
2644 KB |
Output is correct |
40 |
Correct |
3 ms |
2644 KB |
Output is correct |
41 |
Correct |
3 ms |
3028 KB |
Output is correct |
42 |
Correct |
2 ms |
2796 KB |
Output is correct |
43 |
Correct |
3 ms |
2792 KB |
Output is correct |
44 |
Correct |
2 ms |
2644 KB |
Output is correct |
45 |
Correct |
2 ms |
2772 KB |
Output is correct |
46 |
Correct |
2 ms |
2656 KB |
Output is correct |
47 |
Correct |
3 ms |
2900 KB |
Output is correct |
48 |
Correct |
22 ms |
7400 KB |
Output is correct |
49 |
Correct |
24 ms |
8664 KB |
Output is correct |
50 |
Correct |
22 ms |
8928 KB |
Output is correct |
51 |
Correct |
24 ms |
8808 KB |
Output is correct |
52 |
Correct |
22 ms |
8804 KB |
Output is correct |
53 |
Correct |
39 ms |
14412 KB |
Output is correct |
54 |
Correct |
6 ms |
3796 KB |
Output is correct |
55 |
Correct |
14 ms |
6228 KB |
Output is correct |
56 |
Correct |
2 ms |
2772 KB |
Output is correct |
57 |
Correct |
6 ms |
3820 KB |
Output is correct |
58 |
Correct |
4 ms |
3516 KB |
Output is correct |
59 |
Correct |
99 ms |
30116 KB |
Output is correct |
60 |
Correct |
129 ms |
39228 KB |
Output is correct |
61 |
Correct |
134 ms |
38404 KB |
Output is correct |
62 |
Correct |
149 ms |
38468 KB |
Output is correct |
63 |
Correct |
126 ms |
41756 KB |
Output is correct |
64 |
Correct |
140 ms |
38412 KB |
Output is correct |
65 |
Correct |
147 ms |
38472 KB |
Output is correct |
66 |
Correct |
67 ms |
18252 KB |
Output is correct |
67 |
Correct |
148 ms |
41476 KB |
Output is correct |
68 |
Correct |
80 ms |
31160 KB |
Output is correct |
69 |
Correct |
60 ms |
19716 KB |
Output is correct |
70 |
Correct |
133 ms |
36852 KB |
Output is correct |
71 |
Correct |
2 ms |
2652 KB |
Output is correct |
72 |
Correct |
2 ms |
2652 KB |
Output is correct |
73 |
Correct |
2 ms |
2644 KB |
Output is correct |
74 |
Correct |
2 ms |
2644 KB |
Output is correct |
75 |
Correct |
2 ms |
2644 KB |
Output is correct |
76 |
Correct |
2 ms |
2644 KB |
Output is correct |
77 |
Correct |
21 ms |
15188 KB |
Output is correct |
78 |
Correct |
21 ms |
15084 KB |
Output is correct |
79 |
Correct |
19 ms |
15060 KB |
Output is correct |
80 |
Correct |
19 ms |
15176 KB |
Output is correct |
81 |
Correct |
96 ms |
27932 KB |
Output is correct |
82 |
Correct |
135 ms |
36868 KB |
Output is correct |
83 |
Correct |
162 ms |
37448 KB |
Output is correct |
84 |
Correct |
169 ms |
43200 KB |
Output is correct |
85 |
Correct |
164 ms |
44128 KB |
Output is correct |
86 |
Correct |
228 ms |
54384 KB |
Output is correct |
87 |
Correct |
219 ms |
55316 KB |
Output is correct |
88 |
Correct |
2 ms |
2652 KB |
Output is correct |
89 |
Correct |
218 ms |
55512 KB |
Output is correct |
90 |
Correct |
211 ms |
51580 KB |
Output is correct |
91 |
Correct |
171 ms |
52404 KB |
Output is correct |