#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using ll = long long;
const ll N = 3e5 + 10;
const ll INF = 1e9;
ll n, m;
vector<pair<ll,ll> > fish[N];
ll get(ll x,ll y){
return (upper_bound(all(fish[x]), make_pair(y, INF)) - 1)->second;
}
vector<ll> A[N];
ll max_weights(int nn, int mm, vector<int> X, vector<int> Y,vector<int> W) {
n = nn;
m = mm;
for(ll i =0 ;i<m;i++){
fish[X[i] + 1].pb({Y[i], W[i]});
}
fish[0] = {make_pair(-1, 0)};
for(ll i = 1;i<=n;i++){
fish[i].pb({-1, 0});
sort(all(fish[i]));
for(ll j = 1;j< fish[i].size();j++)fish[i][j].second += fish[i][j-1].second;
}
fish[n + 1] = {make_pair(-1, 0)};
A[0] = {-1};
for(ll i = 1;i<=n;i++){
for(auto u : fish[i-1]){
A[i].pb({u.first});
}
for(auto u : fish[i+1]){
A[i].pb({u.first});
}
sort(all(A[i]));
A[i].erase(unique(all(A[i])), A[i].end());
}
A[n+1] = {-1};
vector<ll>dpu = {0}, dpd = {0};
//assert(0);
for(ll i = 1;i<=n+1;i++){
vector<ll> ndpu(A[i].size());
ll pref = 0;
ll ind = 0;
//cout<<i<<endl;
for(ll j = 0;j < A[i].size();j++){
//cout<<j<<endl;
ll x = A[i][j];
while(ind < A[i-1].size() && A[i-1][ind] <= x){
pref = max(pref, dpu[ind] - get(i-1, A[i-1][ind]));
++ind;
}
ndpu[j] = max(pref + get(i-1, x), dpd[0]);
}
vector<ll> ndpd(A[i].size());
ll suff = 0;
ind = A[i-1].size();
for(ll j = A[i].size() - 1;j >= 0; j--){
ll x = A[i][j];
while(ind && A[i-1][ind - 1] >= x){
--ind;
suff = max(suff, max(dpu[ind], dpd[ind]) + get(i, A[i-1][ind]));
}
ndpd[j] = suff - get(i, x);
}
swap(dpu, ndpu);
swap(dpd, ndpd);
}
return max(dpu[0], dpd[0]);
}
Compilation message
fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:41:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(ll j = 1;j< fish[i].size();j++)fish[i][j].second += fish[i][j-1].second;
| ~^~~~~~~~~~~~~~~~
fish.cpp:70:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for(ll j = 0;j < A[i].size();j++){
| ~~^~~~~~~~~~~~~
fish.cpp:74:14: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | while(ind < A[i-1].size() && A[i-1][ind] <= x){
| ~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
57 ms |
26564 KB |
1st lines differ - on the 1st token, expected: '40313272768926', found: '40312711037206' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
14424 KB |
Output is correct |
2 |
Incorrect |
114 ms |
33784 KB |
1st lines differ - on the 1st token, expected: '40604614618209', found: '40604505946872' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
20608 KB |
Output is correct |
2 |
Correct |
22 ms |
20572 KB |
Output is correct |
3 |
Correct |
50 ms |
24152 KB |
Output is correct |
4 |
Correct |
42 ms |
23376 KB |
Output is correct |
5 |
Correct |
65 ms |
28776 KB |
Output is correct |
6 |
Correct |
61 ms |
27984 KB |
Output is correct |
7 |
Correct |
64 ms |
28476 KB |
Output is correct |
8 |
Correct |
65 ms |
28760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
14424 KB |
Output is correct |
2 |
Correct |
4 ms |
14428 KB |
Output is correct |
3 |
Correct |
4 ms |
14624 KB |
Output is correct |
4 |
Correct |
4 ms |
14516 KB |
Output is correct |
5 |
Correct |
4 ms |
14428 KB |
Output is correct |
6 |
Correct |
4 ms |
14428 KB |
Output is correct |
7 |
Correct |
4 ms |
14424 KB |
Output is correct |
8 |
Correct |
4 ms |
14424 KB |
Output is correct |
9 |
Incorrect |
5 ms |
14424 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '162008654471' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
14424 KB |
Output is correct |
2 |
Correct |
4 ms |
14428 KB |
Output is correct |
3 |
Correct |
4 ms |
14624 KB |
Output is correct |
4 |
Correct |
4 ms |
14516 KB |
Output is correct |
5 |
Correct |
4 ms |
14428 KB |
Output is correct |
6 |
Correct |
4 ms |
14428 KB |
Output is correct |
7 |
Correct |
4 ms |
14424 KB |
Output is correct |
8 |
Correct |
4 ms |
14424 KB |
Output is correct |
9 |
Incorrect |
5 ms |
14424 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '162008654471' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
14424 KB |
Output is correct |
2 |
Correct |
4 ms |
14428 KB |
Output is correct |
3 |
Correct |
4 ms |
14624 KB |
Output is correct |
4 |
Correct |
4 ms |
14516 KB |
Output is correct |
5 |
Correct |
4 ms |
14428 KB |
Output is correct |
6 |
Correct |
4 ms |
14428 KB |
Output is correct |
7 |
Correct |
4 ms |
14424 KB |
Output is correct |
8 |
Correct |
4 ms |
14424 KB |
Output is correct |
9 |
Incorrect |
5 ms |
14424 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '162008654471' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
20608 KB |
Output is correct |
2 |
Correct |
22 ms |
20572 KB |
Output is correct |
3 |
Correct |
50 ms |
24152 KB |
Output is correct |
4 |
Correct |
42 ms |
23376 KB |
Output is correct |
5 |
Correct |
65 ms |
28776 KB |
Output is correct |
6 |
Correct |
61 ms |
27984 KB |
Output is correct |
7 |
Correct |
64 ms |
28476 KB |
Output is correct |
8 |
Correct |
65 ms |
28760 KB |
Output is correct |
9 |
Correct |
65 ms |
28240 KB |
Output is correct |
10 |
Incorrect |
54 ms |
26964 KB |
1st lines differ - on the 1st token, expected: '36454348383152', found: '24383121182523' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
57 ms |
26564 KB |
1st lines differ - on the 1st token, expected: '40313272768926', found: '40312711037206' |
2 |
Halted |
0 ms |
0 KB |
- |