# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1061410 | MarwenElarbi | Catfish Farm (IOI22_fish) | C++17 | 93 ms | 14692 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 <bits/stdc++.h>
#include "fish.h"
using namespace std;
#define pb push_back
#define ll long long
#define fi first
#define se second
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
int n=N;
long long a=0;
long long b=0;
vector<pair<int,int>> tab[2];
for (int i = 0; i < W.size(); ++i)
{
tab[X[i]].pb({Y[i],W[i]});
(X[i] == 0 ? a : b) += W[i];
}
if(N==2) return max(a,b);
sort(tab[0].begin(),tab[0].end());
sort(tab[1].begin(),tab[1].end());
long long pre[n];
long long suf[n];
int j=0;
for (int i = 0; i < n; ++i)
{
pre[i]=0;
if(j<tab[0].size()&&tab[0][j].fi==i){
pre[i]=tab[0][j++].se;
}
if(i) pre[i]+=pre[i-1];
}
j=tab[1].size()-1;
for (int i = n-1; i >= 0; --i)
{
suf[i]=0;
if(j>=0&&tab[1][j].fi==i){
suf[i]=tab[1][j--].se;
}
if(i<n-1) suf[i]+=suf[i+1];
}
long long ans=suf[0];
for (int i = 0; i < n-1; ++i)
{
ans=max(ans,suf[i+1]+pre[i]);
}
ans=max(ans,pre[n-1]);
return ans;
}
Compilation message (stderr)
# | 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... |