#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
typedef long long ll;
#define sz(x) (int) (x).size()
#define all(x) (x).begin(), (x).end()
#define pb push_back
int N, M;
vi X, Y, W;
bool cmp(int a, int b) { // compare two fish in the same col
return Y[a] < Y[b];
}
ll max_weights(int _N, int _M, vi _X, vi _Y, vi _W) {
N = _N; M = _M; X = _X; Y = _Y; W = _W;
// subtask 2: x[i] <= 1: either use everything in col0, or col1 (as using 1 means you cant use the other)
ll c0 = 0, c1 = 0;
vi f0, f1;
for (int i = 0; i < M; i++) {
// cout << "i: " << i << " x: " << X[i] << " y: " << Y[i] << " W: " << W[i] << "\n";
if (X[i] == 0) {
c0 += W[i];
f0.pb(i);
} else {
c1 += W[i];
f1.pb(i);
}
}
sort(all(f0), cmp);
sort(all(f1), cmp);
int Z = sz(f0), O = sz(f1);
// cout << "Z: " << Z << " O: " << O << "\n";
int i = 0, j = 0;
ll v = c1;
ll ans = v;
while (i < Z || j < O) {
if (i >= Z || ((j < O) && Y[f1[j]] < Y[f0[i]])) {
v -= W[f1[j]];
j++;
} else if (j >= O || ((i < Z) && Y[f0[i]] < Y[f1[j]])) {
v += W[f0[i]];
ans = max(ans, v);
i++;
} else {
break;
}
}
return ans;
}
# | 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... |