#include "fish.h"
#include<bits/stdc++.h>
using namespace std;
#define int long long int
vector<vector<int>> ind;
vector<vector<pair<int, int>>> pref;
int query(int i, int j) {
return (upper_bound(pref[i].begin(), pref[i].end(), std::make_pair(j, LLONG_MAX)) - 1)->second;
}
int max_weights(int32_t N, int32_t M, vector<int32_t> X, vector<int32_t> Y, vector<int32_t> W) {
int n = N, m = M;
pref.resize(n+5, vector<pair<int, int>>(1, {INT64_MIN, 0}));
ind.resize(n+5);
for (int i = 0; i < m; i++) {
pref[X[i]+1].push_back({Y[i], W[i]});
}
for (int i = 1; i <= n; i++) {
sort(pref[i].begin(), pref[i].end());
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j < pref[i].size(); i++) {
pref[i][j].second += pref[i][j-1].second;
}
}
ind[0].push_back(-1);
ind[n+1].push_back(-1);
for (int i = 1; i <= n; i++) {
for (auto [a, b] : pref[i-1]) {
ind[i].push_back(max(-1LL, a));
}
for (auto [a, b] : pref[i+1]) {
ind[i].push_back(max(-1LL, a));
}
sort(ind[i].begin(), ind[i].end());
ind[i].erase(unique(ind[i].begin(), ind[i].end()), ind[i].end());
}
vector<int> dp0(1, 0), dp1(1, 0); // 0 is increasing, 1 is decreasing, increasing can go to decreasing, decreasing cant go to increasing if next to eachother
for (int i = 1; i <= n+1; i++) {
vector<int> tdp0(ind[i].size()+5, 0), tdp1(ind[i].size()+5, 0);
int v = 0, k = 0;
for (int j = 0; j < ind[i].size(); j++) {
while(k < ind[i-1].size() && ind[i-1][k] <= ind[i][j]) {
v = max(v, dp0[k]-query(i-1, ind[i-1][k]));
k++;
}
tdp0[j] = max(v+query(i-1, ind[i][j]), dp1[0]);
}
v = 0, k = ind[i-1].size();
for (int j = ind[i].size()-1; j >= 0; j--) {
while(k > 0 && ind[i-1][k-1] >= ind[i][j]) {
k--;
v = max(v, max(dp0[k], dp1[k])+query(i, ind[i-1][k]));
}
tdp1[j] = v-query(i, ind[i][j]);
}
swap(dp0, tdp0);
swap(dp1, tdp1);
}
int ans = max(dp0[0], dp1[0]);
return ans;
}
Compilation message
fish.cpp: In function 'long long int max_weights(int32_t, int32_t, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:21:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for (int j = 1; j < pref[i].size(); i++) {
| ~~^~~~~~~~~~~~~~~~
fish.cpp:41:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (int j = 0; j < ind[i].size(); j++) {
| ~~^~~~~~~~~~~~~~~
fish.cpp:42:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | while(k < ind[i-1].size() && ind[i-1][k] <= ind[i][j]) {
| ~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
51 ms |
16232 KB |
1st lines differ - on the 1st token, expected: '40313272768926', found: '999990243' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
97 ms |
22636 KB |
1st lines differ - on the 1st token, expected: '40604614618209', found: '1991782577' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
11356 KB |
Output is correct |
2 |
Correct |
17 ms |
11268 KB |
Output is correct |
3 |
Correct |
38 ms |
14228 KB |
Output is correct |
4 |
Correct |
32 ms |
13912 KB |
Output is correct |
5 |
Correct |
59 ms |
18712 KB |
Output is correct |
6 |
Correct |
51 ms |
18512 KB |
Output is correct |
7 |
Correct |
52 ms |
18768 KB |
Output is correct |
8 |
Correct |
55 ms |
18772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
436 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '79763797371' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
436 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '79763797371' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
436 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '79763797371' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
11356 KB |
Output is correct |
2 |
Correct |
17 ms |
11268 KB |
Output is correct |
3 |
Correct |
38 ms |
14228 KB |
Output is correct |
4 |
Correct |
32 ms |
13912 KB |
Output is correct |
5 |
Correct |
59 ms |
18712 KB |
Output is correct |
6 |
Correct |
51 ms |
18512 KB |
Output is correct |
7 |
Correct |
52 ms |
18768 KB |
Output is correct |
8 |
Correct |
55 ms |
18772 KB |
Output is correct |
9 |
Correct |
58 ms |
18768 KB |
Output is correct |
10 |
Incorrect |
45 ms |
14416 KB |
1st lines differ - on the 1st token, expected: '36454348383152', found: '23310694292708' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
51 ms |
16232 KB |
1st lines differ - on the 1st token, expected: '40313272768926', found: '999990243' |
2 |
Halted |
0 ms |
0 KB |
- |