#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;
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({N+1,0});
V[i].push_back({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++)
{
if(h<V[i-2].size()&&V[i-2][h].y<=V[i][j].y-1)
{
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--)
{
if(h>=0&&V[i][j].y-1<=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].l);
V[i][j].wynik2=V[i][j].wynik;
}
}
h=0;maxx=0;
for(int j=0;j<V[i].size();j++)
{
if(h<V[i-1].size()&&V[i-1][h].y<=V[i][j].y-1)
{
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--)
{
if(h>=0&&V[i][j].y-1<=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);
}
/**for(int j=0;j<V[i].size();j++)
{
cout<<"x="<<i-1<<" y="<<V[i][j].y-1<<" wynik="<<V[i][j].wynik<<endl;
}**/
}
return WYNIK;
}
/**int main()
{ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
long long w=max_weights(5, 4, {0, 1, 4, 3}, {2, 1, 4, 3}, {5, 2, 1, 3});
cout<<w<<endl;
return 0;
}**/
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:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<RYBA>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | if(h<V[i-2].size()&&V[i-2][h].y<=V[i][j].y-1)
| ~^~~~~~~~~~~~~~
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:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<RYBA>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
98 | if(h<V[i-1].size()&&V[i-1][h].y<=V[i][j].y-1)
| ~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
20152 KB |
Output is correct |
2 |
Correct |
68 ms |
22988 KB |
Output is correct |
3 |
Correct |
25 ms |
15152 KB |
Output is correct |
4 |
Correct |
20 ms |
15116 KB |
Output is correct |
5 |
Correct |
157 ms |
38596 KB |
Output is correct |
6 |
Correct |
196 ms |
47768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
15060 KB |
Output is correct |
2 |
Correct |
22 ms |
15072 KB |
Output is correct |
3 |
Incorrect |
44 ms |
21384 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '20897672610412' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
15060 KB |
Output is correct |
2 |
Correct |
22 ms |
15072 KB |
Output is correct |
3 |
Incorrect |
44 ms |
21384 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '20897672610412' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
20152 KB |
Output is correct |
2 |
Correct |
68 ms |
22988 KB |
Output is correct |
3 |
Correct |
25 ms |
15152 KB |
Output is correct |
4 |
Correct |
20 ms |
15116 KB |
Output is correct |
5 |
Correct |
157 ms |
38596 KB |
Output is correct |
6 |
Correct |
196 ms |
47768 KB |
Output is correct |
7 |
Incorrect |
2 ms |
2644 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
8 |
Halted |
0 ms |
0 KB |
- |