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;
#define ll long long
#define ln '\n'
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
if (N <= 2){
ll r0, r1; r0 = r1 = 0LL;
for (int i = 0; i < M; i++){
if (X[i] == 1) r1 += W[i];
else r0 += W[i];
}
return max(r0, r1);
} else {
ll r0, r1; r0 = r1 = 0LL;
vector<array<ll, 2>> vec0, vec1;
for (int i = 0; i < M; i++){
if (X[i] == 0) {vec0.push_back({Y[i], W[i]}); r0 += W[i];}
else {vec1.push_back({Y[i], W[i]}); r1 += W[i];}
}
if (vec0.empty()) {return r1;}
if (vec1.empty()) {return r0;}
sort(vec0.begin(), vec0.end());
sort(vec1.begin(), vec1.end());
for (int i = 1; i < vec0.size(); i++) vec0[i][1] += vec0[i-1][1];
for (int i = 1; i < vec1.size(); i++) vec1[i][1] += vec1[i-1][1];
ll ans1 = r1;
array<ll, 2> t;
for (auto& p: vec0){
// cout << p[0] << ' ' << p[1] << ln;
t = {p[0], -1};
int idx = upper_bound(vec1.begin(), vec1.end(), t) - vec1.begin();
idx--;
ll tmp = r1;
if (idx >= 0) tmp -= vec1[idx][1];
ans1 = max(ans1, tmp + p[1]);
}
ll ans0 = r0;
for (auto& p: vec1){
// cout << p[0] << ' ' << p[1] << ln;
t = {p[0], -1};
int idx = upper_bound(vec0.begin(), vec0.end(), t) - vec0.begin();
idx--;
ll tmp = r0;
if (idx >= 0) tmp -= vec0[idx][1];
ans0 = max(ans0, tmp + p[1]);
}
return max(ans0, ans1);
}
}
Compilation message (stderr)
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:39:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for (int i = 1; i < vec0.size(); i++) vec0[i][1] += vec0[i-1][1];
| ~~^~~~~~~~~~~~~
fish.cpp:40:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for (int i = 1; i < vec1.size(); i++) vec1[i][1] += vec1[i-1][1];
| ~~^~~~~~~~~~~~~
# | 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... |