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 <vector>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
long long max_weights(int n, int m, std::vector<int> x, std::vector<int> y,
std::vector<int> w) {
ll sub1 = 1, sub2 = 1, sub3 = 1;
n++;
vector<vector<pair<ll,ll>>> a(n);
vector<vector<ll>> b(n);
for(ll i = 0;i<m;i++){
a[x[i]].push_back({y[i],w[i]});
if(x[i]) b[x[i]-1].push_back(y[i]);
b[x[i]+1].push_back(y[i]);
if(x[i]&1) sub1 = 0;
if(x[i]>1) sub2 = 0;
if(y[i]) sub3 = 0;
}
for(auto &o : a) sort(o.begin(),o.end());
for(auto &o : b) sort(o.begin(),o.end());
if (sub1){
ll ans = 0;
for(ll i : w) ans += i;
return ans;
}
if(sub2){
ll a1 = 0, a2 = 0;
vector<array<ll,3>> o;
for(auto [p,v] : a[0]) a1+=v,o.push_back({p,v,0});
for(auto [p,v] : a[1]) a2+=v,o.push_back({p,v,1});
ll ans = max(a1,a2);
if(n>2){
sort(o.begin(),o.end());
ll dp0 = 0, dp1 = 0;
for(auto &u : o){
if (u[2]==0){
dp0 += u[1];
dp1 = max(dp1,dp0);
}else{
dp1 += u[1];
}
}
ans = max(ans,dp1);
}
return ans;
}
if (sub3){
vector<ll> dp(n+1,0);
for(ll i = 0;i<n;i++){
dp[i+1] = dp[i];
if(a[i].size()){
ll v = a[i][0].second;
if (i>=1&&a[i-1].size()) v += a[i-1][0].second;;
if (i>=3) v += dp[i-3];
dp[i+1] = max(dp[i+1],v);
v = a[i][0].second;
if (i>=2&&a[i-2].size()) v += a[i-2][0].second;;
if (i>=3) v += dp[i-3];
dp[i+1] = max(dp[i+1],v);
}
}
return dp.back();
}
return 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... |