#include "fish.h"
#include <algorithm>
#include <iostream>
#include <cassert>
#include <numeric>
#include <vector>
typedef long long llong;
const int MAXM = 300000 + 10;
const int MAXN = 3000 + 10;
const llong INF = 1e18;
int n, m;
struct Fish
{
int x, y, w;
inline friend bool operator < (const Fish &a, const Fish &b)
{
return a.x < b.x || (a.x == b.x && a.y < b.y);
}
} fish[MAXM];
llong solveOdd()
{
llong ans = 0;
for (int i = 1 ; i <= m ; ++i)
{
ans += fish[i].w;
}
return ans;
}
llong solveX12()
{
llong sum[2];
sum[0] = sum[1] = 0;
for (int i = 1 ; i <= m ; ++i)
{
--fish[i].x;
sum[fish[i].x] += fish[i].w;
}
if (n == 2)
{
return std::max(sum[0], sum[1]);
}
std::sort(fish+1, fish+1+m);
int ptr0 = 1;
int ptr1 = 1;
while (ptr1 <= m && fish[ptr1].x == 0) ptr1++;
if (ptr1 == m+1) return sum[0];
sum[0] = 0;
llong ans = sum[1];
while (ptr0 <= m && fish[ptr0].x == 0)
{
sum[0] += fish[ptr0].w;
while (ptr1 <= m && fish[ptr1].y <= fish[ptr0].y)
{
sum[1] -= fish[ptr1].w;
++ptr1;
}
ans = std::max(ans, sum[0] + sum[1]);
ptr0++;
}
return ans;
}
llong dp2[MAXM][2][2];
llong solveY1()
{
llong ans = 0;
std::sort(fish+1, fish+1+m);
fish[0].x = -1;
dp2[0][1][0] = -INF;
for (int i = 1 ; i <= m ; ++i)
{
dp2[i][0][0] = std::max(dp2[i-1][0][0], dp2[i-1][1][0] + fish[i].w);
dp2[i][1][0] = std::max(dp2[i-1][0][1], dp2[i-1][1][1]);
dp2[i][0][1] = std::max(dp2[i-1][0][0], dp2[i-1][1][0]) + fish[i].w;
dp2[i][1][1] = std::max(dp2[i-1][0][1], dp2[i-1][1][1]);
}
return std::max(dp2[m][0][0], dp2[m][1][0]);
}
llong solveNSmall()
{
llong ans = 0;
return ans;
}
llong max_weights(int N, int M, std::vector <int> X, std::vector <int> Y, std::vector <int> W)
{
n = N;
m = M;
bool isOdd = true;
bool isX01 = true;
bool isY0 = true;
for (int i = 1 ; i <= m ; ++i)
{
++X[i-1];
++Y[i-1];
fish[i].x = X[i-1];
fish[i].y = Y[i-1];
fish[i].w = W[i-1];
isOdd &= (fish[i].x &1);
isX01 &= (fish[i].x <= 2);
isY0 &= (fish[i].y == 1);
}
if (isOdd) return solveOdd();
if (isX01) return solveX12();
if (isY0) return solveY1();
return solveNSmall();
}
Compilation message
fish.cpp: In function 'llong solveY1()':
fish.cpp:78:11: warning: unused variable 'ans' [-Wunused-variable]
78 | llong ans = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
3156 KB |
Output is correct |
2 |
Correct |
33 ms |
3788 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
90 ms |
10852 KB |
Output is correct |
6 |
Correct |
96 ms |
10860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
74 ms |
5936 KB |
Output is correct |
3 |
Correct |
100 ms |
7368 KB |
Output is correct |
4 |
Correct |
37 ms |
3044 KB |
Output is correct |
5 |
Correct |
46 ms |
3788 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
36 ms |
3068 KB |
Output is correct |
13 |
Correct |
56 ms |
3772 KB |
Output is correct |
14 |
Correct |
31 ms |
3192 KB |
Output is correct |
15 |
Correct |
43 ms |
3428 KB |
Output is correct |
16 |
Correct |
31 ms |
3072 KB |
Output is correct |
17 |
Correct |
56 ms |
3452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '882019', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '882019', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
3156 KB |
Output is correct |
2 |
Correct |
33 ms |
3788 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
90 ms |
10852 KB |
Output is correct |
6 |
Correct |
96 ms |
10860 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
74 ms |
5936 KB |
Output is correct |
9 |
Correct |
100 ms |
7368 KB |
Output is correct |
10 |
Correct |
37 ms |
3044 KB |
Output is correct |
11 |
Correct |
46 ms |
3788 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
36 ms |
3068 KB |
Output is correct |
19 |
Correct |
56 ms |
3772 KB |
Output is correct |
20 |
Correct |
31 ms |
3192 KB |
Output is correct |
21 |
Correct |
43 ms |
3428 KB |
Output is correct |
22 |
Correct |
31 ms |
3072 KB |
Output is correct |
23 |
Correct |
56 ms |
3452 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '882019', found: '0' |
26 |
Halted |
0 ms |
0 KB |
- |