#include "fish.h"
#include <assert.h>
#include <algorithm>
#include <numeric>
#include <vector>
using namespace std;
struct Fish {
int x, y, weight;
bool operator<(const Fish& a) const {
return y < a.y; // x == a.x ? y < a.y : x < a.x;
}
};
long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
vector<Fish> all_fish(M);
for (int i = 0; i < M; ++i) {
all_fish[i] = {X[i], Y[i], W[i]};
}
// sort(all_fish.begin(), all_fish.end());
vector<long long> pref_sum0(N + 1), pref_sum1(N + 1);
int pivot = 0;
for (int i = 0; i < M; ++i) {
Fish& a = all_fish[i];
assert(a.x == 0 || a.x == 1);
if (a.x == 0) {
pref_sum0[a.y + 1] = a.weight;
} else {
pref_sum1[a.y + 1] = a.weight;
}
}
// prefix sum
for (int i = 1; i <= N; ++i) {
pref_sum0[i] += pref_sum0[i - 1];
pref_sum1[i] += pref_sum1[i - 1];
}
// find pivot
for (int i = 0; i <= N; ++i) {
if (pref_sum0[i] + pref_sum1[N] - pref_sum1[i] > pref_sum0[pivot] + pref_sum1[N] - pref_sum1[pivot]) {
pivot = i;
}
}
return pref_sum0[pivot] + pref_sum1[N] - pref_sum1[pivot];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
4436 KB |
Output is correct |
2 |
Correct |
40 ms |
5312 KB |
Output is correct |
3 |
Correct |
2 ms |
1748 KB |
Output is correct |
4 |
Correct |
2 ms |
1748 KB |
Output is correct |
5 |
Runtime error |
126 ms |
24924 KB |
Execution killed with signal 6 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
58 ms |
7308 KB |
Output is correct |
3 |
Correct |
75 ms |
8912 KB |
Output is correct |
4 |
Correct |
25 ms |
4424 KB |
Output is correct |
5 |
Correct |
31 ms |
5320 KB |
Output is correct |
6 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '4044', found: '6066' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1748 KB |
Output is correct |
2 |
Runtime error |
2 ms |
3540 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1748 KB |
Output is correct |
2 |
Runtime error |
2 ms |
3540 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
4436 KB |
Output is correct |
2 |
Correct |
40 ms |
5312 KB |
Output is correct |
3 |
Correct |
2 ms |
1748 KB |
Output is correct |
4 |
Correct |
2 ms |
1748 KB |
Output is correct |
5 |
Runtime error |
126 ms |
24924 KB |
Execution killed with signal 6 |
6 |
Halted |
0 ms |
0 KB |
- |