# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
783985 | SoulKnight | Catfish Farm (IOI22_fish) | C++17 | 118 ms | 15576 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 "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 r1, r2; r1 = r2 = 0LL;
for (int i = 0; i < M; i++){
if (X[i] == 1) r2 += W[i];
else r1 += W[i];
}
return max(r1, r2);
} 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 ans = 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];
ans = max(ans, tmp + p[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... |