This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "fish.h"
#include <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;
typedef long long ll;
ll n,m;
struct date
{
ll poz,val;
};
vector<date> myy[100005];
ll dp[3][3005][3005];
bool comp(date a, date b)
{
return a.poz<b.poz;
}
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
n=N;
m=M;
for(int i=0;i<m;i++)
{
ll x=X[i];
ll y=Y[i];
ll w=W[i];
myy[x+1].push_back({y+1,w});
}
for(int i=1;i<=n;i++)
{
myy[i].push_back({0,0});
myy[i].push_back({n+1,0});
sort(myy[i].begin(),myy[i].end(),comp);
}
ll ans=0;
for(int i=2;i<=n;i++)
{
// neutru
ll suma=0;
for(ll j=0;j<myy[i].size();j++)
{
suma+=myy[i][j].val;
ll p=myy[i][j].poz;
for(ll k=0;k<myy[i-1].size();k++)
{
ll p1=myy[i-1][k].poz-1;
if(p1>=p)
dp[0][i][p]=max(dp[0][i][p],suma+max(dp[1][i-1][p1],dp[2][i-1][p1]));
}
if(p==0)
{
for(ll k=0;k<myy[i-1].size();k++)
{
ll p1=myy[i-1][k].poz;
dp[0][i][p]=max(dp[0][i][p],dp[0][i-1][p1]);
}
}
ans=max(ans,dp[0][i][p]);
}
// cresc
for(int j=0;j<myy[i].size();j++)
{
ll p=myy[i][j].poz-1;
if(p<0)
continue;
ll s1=0;
for(ll k=0;k<myy[i-1].size();k++)
{
if(myy[i-1][k].poz<=p)
s1+=myy[i-1][k].val;
}
ll s2=0;
for(ll k=0;k<myy[i-1].size();k++)
{
ll poz=myy[i-1][k].poz-1;
if(poz>=0)
{
ll val=max(dp[0][i-1][poz],dp[1][i-1][poz])+max(0LL,s1-s2);
dp[1][i][p]=max(dp[1][i][p],val);
}
s2+=myy[i-1][k].val;
poz++;
ll val=dp[0][i-1][poz]+max(0LL,s1-s2);
dp[1][i][p]=max(dp[1][i][p],val);
}
ans=max(ans,dp[1][i][p]);
}
// desc
for(int j=0;j<myy[i].size();j++)
{
ll p=myy[i][j].poz-1;
if(p<0)
continue;
ll s2=0;
for(int k=0;k<j;k++)
s2+=myy[i][k].val;
ll poz=0;
ll s1=0;
for(int k=0;k<myy[i-1].size();k++)
{
ll p1=myy[i-1][k].poz-1;
if(p1<0)
continue;
while(poz<myy[i].size()&&myy[i][poz].poz<=p1)
{
s1+=myy[i][poz].val;
poz++;
}
ll val=max(dp[1][i-1][p1],dp[2][i-1][p1])+max(0LL,s1-s2);
dp[2][i][p]=max(dp[2][i][p],val);
}
ans=max(ans,dp[2][i][p]);
}
}
return ans;
}
Compilation message (stderr)
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:38:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(ll j=0;j<myy[i].size();j++)
| ~^~~~~~~~~~~~~~
fish.cpp:42:25: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(ll k=0;k<myy[i-1].size();k++)
| ~^~~~~~~~~~~~~~~~
fish.cpp:50:29: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(ll k=0;k<myy[i-1].size();k++)
| ~^~~~~~~~~~~~~~~~
fish.cpp:60:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for(int j=0;j<myy[i].size();j++)
| ~^~~~~~~~~~~~~~
fish.cpp:66:25: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for(ll k=0;k<myy[i-1].size();k++)
| ~^~~~~~~~~~~~~~~~
fish.cpp:72:25: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for(ll k=0;k<myy[i-1].size();k++)
| ~^~~~~~~~~~~~~~~~
fish.cpp:89:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | for(int j=0;j<myy[i].size();j++)
| ~^~~~~~~~~~~~~~
fish.cpp:99:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
99 | for(int k=0;k<myy[i-1].size();k++)
| ~^~~~~~~~~~~~~~~~
fish.cpp:104:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
104 | while(poz<myy[i].size()&&myy[i][poz].poz<=p1)
| ~~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |