# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
834713 | GordonRemzi007 | Catfish Farm (IOI22_fish) | C++17 | 0 ms | 0 KiB |
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 <iostream>
#include <vector>
#define ll long long
using namespace std;
ll max_weights(ll n, ll m, vector<ll> x, vector<ll> y, vector<ll> w) {
ll res;
if(n == 2) {
ll r0 = 0, r1 = 0;
for(ll i = 0; i < m; i++) {
if(x[i]) r1+=w[i];
else r0+=w[i];
}
res = max(r0, r1);
} else {
vector<ll> pref0(n), pref1(n);
for(int i = 0; i < m; i++) {
if(x[i]) pref1[y[i]] = w[i];
else pref0[y[i]] = w[i];
}
for(int i = 1; i < n; i++) {
pref0[i]+=pref0[i-1];
pref1[i]+=pref1[i-1];
}
res = pref1[n-1];
for(int i = 0; i < n; i++) res = max(res, pref0[i]+pref1[n-1]-pref1[i]);
}
return res;
}