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;
vector<ll> suf;
int lg=myy[i-1].size();
ll maxim=0;
for(int j=lg-1;j>=0;j--)
{
int p1=myy[i-1][j].poz-1;
maxim=max(maxim,max(dp[1][i-1][p1],dp[2][i-1][p1]));
suf.push_back(maxim);
}
reverse(suf.begin(),suf.end());
for(ll j=0;j<myy[i].size();j++)
{
suma+=myy[i][j].val;
ll p=myy[i][j].poz;
ll st=0;
ll dr=myy[i-1].size();
dr--;
while(st<=dr)
{
ll mij=(st+dr)/2;
if(myy[i-1][mij].poz-1>=p)
{
dp[0][i][p]=max(dp[0][i][p],suma+suf[mij]);
dr=mij-1;
}
else
st=mij+1;
}
ans=max(ans,dp[0][i][p]);
}
vector<ll> prefsum;
suma=0;
for(int j=0;j<myy[i-1].size();j++)
{
suma+=myy[i-1][j].val;
prefsum.push_back(suma);
}
maxim=0;
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=dp[1][i-1][poz]-s2;
maxim=max(maxim,val);
}
s2+=myy[i-1][k].val;
poz++;
ll val=dp[0][i-1][poz]-s2;
maxim=max(maxim,val);
}
// cresc
for(int j=0;j<myy[i].size();j++)
{
ll p=myy[i][j].poz-1;
if(p<0)
continue;
ll s1=0;
ll st=0;
ll dr=myy[i-1].size();
dr--;
while(st<=dr)
{
ll mij=(st+dr)/2;
if(myy[i-1][mij].poz<=p)
{
s1=prefsum[mij];
st=mij+1;
}
else
dr=mij-1;
}
dp[1][i][p]=s1+maxim;
ans=max(ans,dp[1][i][p]);
}
// desc
prefsum.clear();
suma=0;
for(int j=0;j<myy[i].size();j++)
{
suma+=myy[i][j].val;
prefsum.push_back(suma);
}
maxim=0;
for(int k=0;k<myy[i-1].size();k++)
{
ll p1=myy[i-1][k].poz-1;
if(p1<0)
continue;
ll s1=0;
ll st=0;
ll dr=myy[i].size();
dr--;
while(st<=dr)
{
ll mij=(st+dr)/2;
if(myy[i][mij].poz<=p1)
{
s1=prefsum[mij];
st=mij+1;
}
else
dr=mij-1;
}
ll val=max(dp[1][i-1][p1],dp[2][i-1][p1])+s1;
maxim=max(maxim,val);
}
s2=0;
for(int j=0;j<myy[i].size();j++)
{
ll p=myy[i][j].poz-1;
if(p<0)
continue;
ll poz=0;
dp[2][i][p]=maxim-s2;
ans=max(ans,dp[2][i][p]);
s2+=myy[i][j].val;
}
}
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:48: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]
48 | for(ll j=0;j<myy[i].size();j++)
| ~^~~~~~~~~~~~~~
fish.cpp:70:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for(int j=0;j<myy[i-1].size();j++)
| ~^~~~~~~~~~~~~~~~
fish.cpp:77: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]
77 | for(ll k=0;k<myy[i-1].size();k++)
| ~^~~~~~~~~~~~~~~~
fish.cpp:91:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | for(int j=0;j<myy[i].size();j++)
| ~^~~~~~~~~~~~~~
fish.cpp:118:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
118 | for(int j=0;j<myy[i].size();j++)
| ~^~~~~~~~~~~~~~
fish.cpp:124:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
124 | for(int k=0;k<myy[i-1].size();k++)
| ~^~~~~~~~~~~~~~~~
fish.cpp:148:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
148 | for(int j=0;j<myy[i].size();j++)
| ~^~~~~~~~~~~~~~
fish.cpp:153:16: warning: unused variable 'poz' [-Wunused-variable]
153 | ll poz=0;
| ^~~
# | 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... |