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>
using namespace std;
using ll = long long;
ll p2(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
vector<int> a(n,0), b(n,0);
for (int i=0; i<m; ++i) {
if (x[i]==0) a[y[i]]=w[i];
else b[y[i]]=w[i];
}
ll ans=0;
for (int i=0; i<n; ++i) ans+=b[i];
ll cnt=ans;
for (int i=0; i<n; ++i) {
cnt+=a[i]-b[i];
ans=max(ans,cnt);
}
return ans;
}
ll p3(int n, int m, vector<int> x, vector<int> w) {
vector<int> a(n,0);
vector<pair<int,int>> b(n);
for (int i=0; i<n; ++i) b[i]={0,i};
for (int i=0; i<m; ++i) {
b[x[i]]={w[i],x[i]};
a[x[i]]=w[i];
}
sort(b.begin(), b.end());
vector<int> vis(n,0);
ll ans=0;
for (int i=0; i<n; ++i) {
auto it=b[i];
int j=it.second, w=it.first;
for (auto x:a) cout<<x<<' '; cout<<'\n';
//for (auto x:vis) cout<<x<<' '; cout<<'\n';
cout<<j<<' '<<w<<'\n';
if ((j?(vis[j-1]?0:a[j-1]):0) + ((j<n-1)?(vis[j+1]?0:a[j+1]):0) > a[j]) {
ans+=(j?(vis[j-1]?0:a[j-1]):0) + ((j<n-1)?(vis[j+1]?0:a[j+1]):0) - a[j];
//cout<<(j?(vis[j-1]?0:a[j-1]):0)<<' '<<((j<n-1)?(vis[j+1]?0:a[j+1]):0)<<' '<<ans<<'\n';
a[j]=0;
if (j) vis[j-1]=1;
if (j<n-1) vis[j+1]=1;
}
}
return ans;
}
ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
int _p1=1, _p2=1, _p3=1;
ll sum=0;
for (int i=0; i<m; ++i) {
_p1&=!(x[i]&1);
_p2&=x[i]<=1;
_p3&=y[i]==0;
sum+=w[i];
}
if (_p1) return sum;
if (_p2) return p2(n,m,x,y,w);
if (_p3) return p3(n,m,x,w);
}
Compilation message (stderr)
fish.cpp: In function 'll p3(int, int, std::vector<int>, std::vector<int>)':
fish.cpp:41:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
41 | for (auto x:a) cout<<x<<' '; cout<<'\n';
| ^~~
fish.cpp:41:34: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
41 | for (auto x:a) cout<<x<<' '; cout<<'\n';
| ^~~~
fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:71:1: warning: control reaches end of non-void function [-Wreturn-type]
71 | }
| ^
# | 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... |