#include <bits/stdc++.h>
//#include <fish.h>
using namespace std;
int64_t max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
for (int i = 0; i < X.size(); i++) {
X[i]++;
}
int my = 0;
for (int y: Y) {
my = max(my, y);
}
my ++;
vector<pair<int,int64_t> > vec[N + 10];
map<int,int64_t> s[N + 10];
for (int i = 0; i < X.size(); i++) {
vec[X[i]].push_back(make_pair(Y[i], W[i]));
s[X[i]][Y[i]] = W[i];
}
int64_t pref[N + 10][my + 2];
for (int i = 0; i <= N + 9; i++) {
pref[i][0] = 0;
for (int j = 1; j <= my + 1; j++) {
pref[i][j] = pref[i][j - 1];
if (s[i].count(j - 1)) pref[i][j] += s[i][j - 1];
}
}
int64_t dp[N + 1][my + 1][3];
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= my; j++) {
for (int d = 0; d < 3; d++) {
dp[i][j][d] = -1e17;
}
}
}
dp[0][0][0] = 0;
//0 --> stagnant
//1 --> increasing
//2 --> decreasing
for (int i = 1; i <= N; i++) {
for (int p = 0; p <= my; p++) {
dp[i][0][0] = max(dp[i][0][0], dp[i - 1][p][0]);
}
int64_t myMax1 = -1e17;
int64_t myMax2 = dp[i - 1][0][0] - pref[i - 1][0];
for (int cur = 1; cur <= my; cur++) {
dp[i][cur][0] = max(dp[i][cur][0], max(dp[i - 1][cur][1], dp[i - 1][cur][2]));
dp[i][cur][1] = max(dp[i][cur][1], myMax1 = max(myMax1, dp[i - 1][cur][1] - pref[i][cur] - pref[i - 1][cur]) + pref[i + 1][cur] + pref[i - 1][cur]);
for (int d = 1; d <= 2; d++) {
dp[i][cur][d] = max(dp[i][cur][d], myMax2 = max(myMax2, dp[i - 1][cur][0] - pref[i - 1][cur]) + pref[i - 1][cur] + pref[i + 1][cur]);
}
}
int64_t myMax3 = -1e17, myMax4 = -1e17;
for (int cur = my; cur >= 1; cur--) {
dp[i][cur][2] = max(dp[i][cur][2], myMax4 = max(myMax4, dp[i - 1][cur][2]) - pref[i][cur] + pref[i + 1][cur]);
for (int d = 1; d <= 2; d++) {
dp[i][cur][d] = max(dp[i][cur][d], myMax3 = max(myMax3, dp[i - 1][cur][0]) + pref[i + 1][cur]);
}
}
}
int64_t myMax = 0;
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= my; j++) {
for (int d = 0; d <= 2; d++) {
myMax = max(myMax, dp[i][j][d]);
}
}
}
return myMax;
}
Compilation message
fish.cpp: In function 'int64_t max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:5:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
5 | for (int i = 0; i < X.size(); i++) {
| ~~^~~~~~~~~~
fish.cpp:15:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | for (int i = 0; i < X.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
796 ms |
2097152 KB |
Execution killed with signal 9 |
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: '2', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
14292 KB |
1st lines differ - on the 1st token, expected: '10082010', found: '20164020' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '9' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '9' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '9' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
14292 KB |
1st lines differ - on the 1st token, expected: '10082010', found: '20164020' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
796 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |