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;
constexpr size_t N = 3000;
struct state
{
int64_t zero;
};
long long max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w)
{
// subtask 1
{
bool all_even = 1;
for (size_t i = 0; i < m; ++i)
all_even &= !(x[i] & 1);
if (all_even)
{
int64_t sum = 0;
for (size_t i = 0; i < m; ++i)
sum += w[i];
return sum;
}
}
// subtask 2
{
bool leq1 = 1;
for (size_t i = 0; i < m; ++i)
leq1 &= x[i] <= 1;
if (leq1)
{
int64_t z = 0, t = 0;
vector<pair<int, int>> zero, one;
for (size_t i = 0; i < m; ++i)
if (x[i])
one.emplace_back(y[i], w[i]), z += w[i];
else
zero.emplace_back(y[i], w[i]), t += w[i];
if (n == 2)
return max(t, z);
sort(one.begin(), one.end());
sort(zero.begin(), zero.end());
int64_t ans = z;
auto it = zero.begin(), jt = one.begin();
for (int i = 0; i <= n && (it != zero.end() || jt != one.end()); ++i)
{
if (it != zero.end() && it->first < i)
z += it->second, ++it;
if (jt != one.end() && jt->first < i)
z -= jt->second, ++jt;
ans = max(ans, z);
}
return ans;
}
}
}
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:18:30: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
18 | for (size_t i = 0; i < m; ++i)
| ~~^~~
fish.cpp:23:34: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
23 | for (size_t i = 0; i < m; ++i)
| ~~^~~
fish.cpp:32:30: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
32 | for (size_t i = 0; i < m; ++i)
| ~~^~~
fish.cpp:38:34: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
38 | for (size_t i = 0; i < m; ++i)
| ~~^~~
fish.cpp:64:1: warning: control reaches end of non-void function [-Wreturn-type]
64 | }
| ^
# | 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... |