#include "fish.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
//#define int long long
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
if (N <= 2) {
int ans[2];
ans[0] = 0; ans[1] = 0;
for (int i = 0; i < M; i++) ans[X[i]] += W[i];
return max(ans[0], ans[1]);
}
std::map<std::pair<int, int>, int> v; for (int i = 0; i < M; i++) v[{X[i], Y[i]}] = W[i];
vector<int> h[2]; h[0] = {}; h[1] = {};
for (int i = 0; i < M; i++) h[X[i]].push_back(Y[i]);
std::sort(h[0].begin(), h[0].end()); std::sort(h[1].begin(), h[1].end());
long long og = 0; for (size_t i = 0; i < h[1].size(); i++) og += v[{1, h[1][i]}];
long long cur = 0; long long ans = 0;
size_t ptr = 0;
//cout << og << " og\n";
//cout << cur << " cur\n";
for (size_t i = 0; i < h[0].size(); i++) {
cur += v[{0, h[0][i]}];
while (ptr < h[1].size()) {
if (h[1][ptr] > h[0][i]) break;
cur -= v[{1, h[1][ptr]}];
ptr++;
}
//cout << cur << " cur\n";
ans = max(ans, og + cur);
}
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... |