#include "fish.h"
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <cmath>
#include <random>
#include <chrono>
#include <iomanip>
#include <iostream>
#include <bitset>
#include <cmath>
#include <string>
using namespace std;
int log_ = 23;
long long inf = 8000000007000000007ll;
int mod = 1000000007;
int p = 523;
#include <vector>
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W)
{
int n = N;
vector <vector <pair <int, int>>> vp(n);
vector <long long> sum(n);
for (int i = 0; i < X.size(); i++)
{
vp[X[i]].push_back({ Y[i] , W[i] });
sum[X[i]] += W[i];
}
for (int i = 0; i < n; i++)
{
sort(vp[i].begin(), vp[i].end());
}
vector <vector <long long>> dp0(n);
vector <vector <long long>> dp1(n);
for (int i = 0; i < n; i++)
{
dp0[i].resize(vp[i].size());
dp1[i].resize(vp[i].size());
}
long long ans = 0;
long long mx_ = 0;
vector <long long> dp(n);
for (int i = 0; i < n; i++)
{
dp[i] = mx_;
if (i >= 4)
{
mx_ = max(mx_, dp[i - 3] + sum[i - 3] + sum[i - 2]);
}
for (int j = 0; j < vp[i].size(); j++)
{
ans = max(ans , mx_ + vp[i][j].second);
}
if ((i > 0) and (vp[i].size() > 0))
{
if (i != n - 1)
{
int ind = 0;
int sz = vp[i].size();
long long mx = 0;
for (int j = 0; j < sz; j++)
{
while ((ind < vp[i - 1].size()) and (vp[i - 1][ind].first < vp[i][j].first))
{
mx = max(mx, dp0[i - 1][ind]);
ind++;
}
mx = max(mx, mx_);
dp0[i][j] = mx + vp[i][j].second;
mx = max(mx, dp0[i][j]);
}
}
if (i != 0)
{
int ind = vp[i - 1].size();
ind--;
int sz = vp[i].size();
long long mx1 = 0;
long long mx2 = 0;
for (int j = sz - 1; j >= 0; j--)
{
while ((ind >= 0) and (vp[i - 1][ind].first > vp[i][j].first))
{
mx1 = max(mx1, dp1[i - 1][ind]);
ind--;
}
mx1 = max(mx1, mx_);
mx2 = max(mx2, mx_);
dp1[i][j] = max(mx1 , mx2) + vp[i][j].second;
if (i < n - 1)
{
dp0[i][j] = max(dp0[i][j], mx1+ vp[i][j].second);
}
if ((ind >= 0) and(i != n - 1))
{
if (vp[i - 1][ind].first == vp[i][j].first)
{
dp0[i][j] = max(dp1[i - 1][ind] + vp[i][j].second, dp0[i][j]);
}
}
mx2 = max(mx2, dp1[i][j]);
}
}
if (i < n - 1)
{
if (vp[i].size() > 0)
{
long long mx__ = 0;
for (int j = 0; j < vp[i].size(); j++)
{
if (mx__ != 0)
mx__ += vp[i][j].second;
mx__ = max(mx__, dp0[i][j]);
dp0[i][j] = mx__;
}
}
}
}
else
{
long long s = 0;
for (int j = 0; j < vp[i].size(); j++)
{
s += vp[i][j].second;
dp0[i][j] = s;
dp1[i][j] = 0;
}
}
for (int j = 0; j < vp[i].size(); j++)
{
ans = max(ans, dp0[i][j]);
ans = max(ans, dp1[i][j]);
}
if (i - 1 >= 0)
{
for (int j = 0; j < vp[i - 1].size(); j++)
{
mx_ = max(mx_, dp0[i - 1][j]);
mx_ = max(mx_, dp1[i - 1][j]);
}
}
ans = max(ans, mx_);
}
if (n >= 4)
{
mx_ = max(mx_, dp[n - 4] + sum[n - 3] + sum[n - 2]);
}
ans = max(ans, mx_);
return ans;
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:41:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (int i = 0; i < X.size(); i++)
| ~~^~~~~~~~~~
fish.cpp:76:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | for (int j = 0; j < vp[i].size(); j++)
| ~~^~~~~~~~~~~~~~
fish.cpp:95:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | while ((ind < vp[i - 1].size()) and (vp[i - 1][ind].first < vp[i][j].first))
| ~~~~^~~~~~~~~~~~~~~~~~
fish.cpp:158:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
158 | for (int j = 0; j < vp[i].size(); j++)
| ~~^~~~~~~~~~~~~~
fish.cpp:173:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
173 | for (int j = 0; j < vp[i].size(); j++)
| ~~^~~~~~~~~~~~~~
fish.cpp:183:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
183 | for (int j = 0; j < vp[i].size(); j++)
| ~~^~~~~~~~~~~~~~
fish.cpp:191:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
191 | for (int j = 0; j < vp[i - 1].size(); j++)
| ~~^~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
11972 KB |
Output is correct |
2 |
Correct |
30 ms |
13748 KB |
Output is correct |
3 |
Correct |
4 ms |
9040 KB |
Output is correct |
4 |
Correct |
4 ms |
9036 KB |
Output is correct |
5 |
Correct |
84 ms |
23004 KB |
Output is correct |
6 |
Correct |
97 ms |
25928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
61 ms |
15900 KB |
Output is correct |
3 |
Correct |
58 ms |
18612 KB |
Output is correct |
4 |
Correct |
24 ms |
11988 KB |
Output is correct |
5 |
Correct |
29 ms |
13756 KB |
Output is correct |
6 |
Correct |
1 ms |
508 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
5 ms |
9040 KB |
Output is correct |
11 |
Correct |
4 ms |
9040 KB |
Output is correct |
12 |
Correct |
24 ms |
12012 KB |
Output is correct |
13 |
Correct |
32 ms |
13756 KB |
Output is correct |
14 |
Correct |
26 ms |
13100 KB |
Output is correct |
15 |
Correct |
27 ms |
13288 KB |
Output is correct |
16 |
Correct |
24 ms |
12228 KB |
Output is correct |
17 |
Correct |
27 ms |
13396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
9040 KB |
Output is correct |
2 |
Correct |
4 ms |
9040 KB |
Output is correct |
3 |
Correct |
25 ms |
14396 KB |
Output is correct |
4 |
Correct |
17 ms |
13136 KB |
Output is correct |
5 |
Correct |
42 ms |
20556 KB |
Output is correct |
6 |
Correct |
40 ms |
20560 KB |
Output is correct |
7 |
Correct |
41 ms |
20560 KB |
Output is correct |
8 |
Correct |
60 ms |
21616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
508 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
592 KB |
Output is correct |
11 |
Incorrect |
1 ms |
336 KB |
1st lines differ - on the 1st token, expected: '278622587073', found: '277681576679' |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
508 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
592 KB |
Output is correct |
11 |
Incorrect |
1 ms |
336 KB |
1st lines differ - on the 1st token, expected: '278622587073', found: '277681576679' |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
508 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
592 KB |
Output is correct |
11 |
Incorrect |
1 ms |
336 KB |
1st lines differ - on the 1st token, expected: '278622587073', found: '277681576679' |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
9040 KB |
Output is correct |
2 |
Correct |
4 ms |
9040 KB |
Output is correct |
3 |
Correct |
25 ms |
14396 KB |
Output is correct |
4 |
Correct |
17 ms |
13136 KB |
Output is correct |
5 |
Correct |
42 ms |
20556 KB |
Output is correct |
6 |
Correct |
40 ms |
20560 KB |
Output is correct |
7 |
Correct |
41 ms |
20560 KB |
Output is correct |
8 |
Correct |
60 ms |
21616 KB |
Output is correct |
9 |
Correct |
40 ms |
20560 KB |
Output is correct |
10 |
Correct |
33 ms |
11556 KB |
Output is correct |
11 |
Correct |
67 ms |
25160 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
4 ms |
9040 KB |
Output is correct |
19 |
Correct |
4 ms |
9104 KB |
Output is correct |
20 |
Correct |
5 ms |
9040 KB |
Output is correct |
21 |
Correct |
4 ms |
9056 KB |
Output is correct |
22 |
Incorrect |
44 ms |
18724 KB |
1st lines differ - on the 1st token, expected: '45561826463480', found: '45259457816092' |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
11972 KB |
Output is correct |
2 |
Correct |
30 ms |
13748 KB |
Output is correct |
3 |
Correct |
4 ms |
9040 KB |
Output is correct |
4 |
Correct |
4 ms |
9036 KB |
Output is correct |
5 |
Correct |
84 ms |
23004 KB |
Output is correct |
6 |
Correct |
97 ms |
25928 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
61 ms |
15900 KB |
Output is correct |
9 |
Correct |
58 ms |
18612 KB |
Output is correct |
10 |
Correct |
24 ms |
11988 KB |
Output is correct |
11 |
Correct |
29 ms |
13756 KB |
Output is correct |
12 |
Correct |
1 ms |
508 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
5 ms |
9040 KB |
Output is correct |
17 |
Correct |
4 ms |
9040 KB |
Output is correct |
18 |
Correct |
24 ms |
12012 KB |
Output is correct |
19 |
Correct |
32 ms |
13756 KB |
Output is correct |
20 |
Correct |
26 ms |
13100 KB |
Output is correct |
21 |
Correct |
27 ms |
13288 KB |
Output is correct |
22 |
Correct |
24 ms |
12228 KB |
Output is correct |
23 |
Correct |
27 ms |
13396 KB |
Output is correct |
24 |
Correct |
3 ms |
9040 KB |
Output is correct |
25 |
Correct |
4 ms |
9040 KB |
Output is correct |
26 |
Correct |
25 ms |
14396 KB |
Output is correct |
27 |
Correct |
17 ms |
13136 KB |
Output is correct |
28 |
Correct |
42 ms |
20556 KB |
Output is correct |
29 |
Correct |
40 ms |
20560 KB |
Output is correct |
30 |
Correct |
41 ms |
20560 KB |
Output is correct |
31 |
Correct |
60 ms |
21616 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
0 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
508 KB |
Output is correct |
37 |
Correct |
1 ms |
336 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
592 KB |
Output is correct |
42 |
Incorrect |
1 ms |
336 KB |
1st lines differ - on the 1st token, expected: '278622587073', found: '277681576679' |
43 |
Halted |
0 ms |
0 KB |
- |